How to project a point on to a sphere

George picture George · Mar 7, 2012 · Viewed 15.9k times · Source

If i have a point (x,y,z) how to project it on to a sphere(x0,y0,z0,radius) (on its surface). My input will be the coordinates of point and sphere. The output should be the coordinates of the projected point on sphere.

Just convert from cartesian to spherical coordinates?

Answer

Stephen Canon picture Stephen Canon · Mar 7, 2012

For the simplest projection (along the line connecting the point to the center of the sphere):

  1. Write the point in a coordinate system centered at the center of the sphere (x0,y0,z0):

    P = (x',y',z') = (x - x0, y - y0, z - z0)

  2. Compute the length of this vector:

    |P| = sqrt(x'^2 + y'^2 + z'^2)

  3. Scale the vector so that it has length equal to the radius of the sphere:

    Q = (radius/|P|)*P

  4. And change back to your original coordinate system to get the projection:

    R = Q + (x0,y0,z0)