How to project a point on to a sphere

六眼飞鱼酱① 提交于 2019-12-01 15:20:33
Stephen Canon

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)

Basically you want to construct a line going through the spheres centre and the point. Then you intersect this line with the sphere and you have your projection point.

In greater detail:

Let p be the point, s the sphere's centre and r the radius then x = s + r*(p-s)/(norm(p-s)) where x is the point you are looking for. The implementation is left to you.

I agree that the spherical coordinate approach will work as well but is computationally more demanding. In the above formula the only non-trivial operation is the square root for the norm.

It works if you set the coordinates of the center of the sphere as origin of the system (x0, y0, z0). So you will have the coordinates of the point referred to that origin (Xp', Yp', Zp'), and converting the coordinates to polar, you discard the radius (distance between the center of the sphere and the point) and the angles will define the projection.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!