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
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.