title: Generate a point within a sphere of a certain radius that's around a SPECIFIC given point (not at 0,0,0) - Python
body: <p>I have a function that creates a uniform random point inside a sphere of a specific radius:</p>
  
  <pre><code>radius = 5
  r = radius * ( numpy.random.random()**(1./3.) )  
  phi = numpy.random.uniform(0,2*numpy.pi) 
  costheta = numpy.random.uniform(-1,1) 
  theta = numpy.arccos(costheta) 
  x = numpy.sin(theta) * numpy.cos(phi) 
  y = numpy.sin(theta) * numpy.sin(phi)
  z = numpy.cos(theta)
  point = numpy.array([x, y, z]) * r`
  </code></pre>
  
  <p>However, I'm trying to figure out how to get the point that gets generated to be within a sphere that's around <strong>a specific point</strong> in space rather than where it's being generated at currently around <strong>0,0,0</strong>. I'm not math savvy at all so I'm not sure how to do this. 
  There are plenty of examples of how to generate a random point in a sphere of a specific radius (ie <a href="https://stackoverflow.com/questions/5837572/generate-a-random-point-within-a-circle-uniformly">Generate a random point within a circle (uniformly)</a>, but I haven't seen any in python that state how to do so inside a radius that's around a user specified point (or perhaps I'm just misunderstanding the math that gets used...). </p>
  
  <p>There was one question that got asked/answered here (<a href="https://stackoverflow.com/questions/26895097/generate-a-random-cluster-of-points-around-a-given-point-python">generate a random cluster of points around a given point python</a>) but this didn't really help, there were some other somewhat similar questions but they were in either Java or C# (ie <a href="https://stackoverflow.com/questions/29264960/randomly-generate-clustered-points-given-a-center-coordinate-in-3d">Randomly generate clustered points given a center coordinate in 3D</a>). </p>
  
  <p>I put in a simple drawing of what I have right now (on the left) and what I'm trying to do (on the right).<a href="https://i.stack.imgur.com/K2NPX.png" rel="nofollow noreferrer">differentOrigin</a></p>
  
  <p>Any help or examples would be greatly appreciated!!</p>