How to project a point on to a sphere

后端 未结 3 1761
情话喂你
情话喂你 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:35

    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.

提交回复
热议问题