How to project a point on a sphere

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

Just convert from Cartesian to spherical?

+4
source share
3 answers

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

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

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

  • Calculate the length of this vector:

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

  • Scale the vector so that it has a length equal to the radius of the sphere:

    Q = (radius / | P |) * P

  • And go back to the original coordinate system to get the projection:

    R = Q + (x0, y0, z0)

+15
source

Basically, you want to build a line through the center of the spheres and the point. Then you cross this line with the sphere, and you have a projection point.

In details:

Let p be the point, s center of the sphere and r radius, then x = s + r*(ps)/(norm(ps)) , where x is the point you are looking for. Implementation remains for you.

I agree that a spherical coordinate approach will work as well, but is more computationally complex. In the above formula, the only nontrivial operation is the square root of the norm.

+3
source

It works if you set the coordinates of the center of the sphere as the beginning of the system (x0, y0, z0). Thus, you will have the coordinates of the point related to this origin (Xp ', Yp', Zp '), and converting the coordinates to polar, you drop the radius (the distance between the center of the sphere and the point) and the angles will determine the projection.

0
source

Source: https://habr.com/ru/post/1400230/


All Articles