How to project a point on to a sphere

后端 未结 3 1742
情话喂你
情话喂你 2021-01-17 13:31

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

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-17 13:49

    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)

提交回复
热议问题