0

I'm new to Python and I would like to get 1000 of parameters that satisfy a given equation.

More precisely, below is the equation of the sphere, assume the position of the sphere center(x0, y0, z0) and its radius are both given.

(x - x0)^2 + (y - y0)^2 + (z - z0)^2 = radius^2

How could I randomly generate a number of (x, y, z) that satisfy the sphere equation in python? Thanks a lot!

  • There is no [tag:python] in the question. – Peter Wood Dec 10 '18 at 09:50
  • Welcome to [so]. This looks like a homework question. While it is OK to ask for homework help on SO, you should at least take some effort to solve the problem yourself, otherwise you don't learn anything. See https://stackoverflow.com/help/on-topic. – Adrian W Dec 10 '18 at 09:54
  • See [this question](https://math.stackexchange.com/questions/1585975/how-to-generate-random-points-on-a-sphere) for methods of using random distributions. Python has various distributions, e.g. [**`uniform`**](https://docs.python.org/3/library/random.html#random.uniform). – Peter Wood Dec 10 '18 at 09:54

1 Answers1

-1

One approach would be to take the center point (x0, y0, z0) and add a random vector of length r to it.

Then the question reduces to "how does one create a random vector of fixed length?". One could create a random vector and normalize it to unit length, and then stretch it to have length r.

Hope that helps, and best of luck!

V. Wase
  • 24
  • 3