How to move a point outside a sphere along a line

geometryvectors

May the coordinates of a sphere with centre C and its radius r be given.
Also a point P, which has to be moved outside the sphere (i.e. onto its surface), if the point is inside the sphere.
P must be moved in the direction of CP = P - C.

I believe this approach is wrong: P_new = C + (r * CP).
The distance between P_new and C has to be r.
By multiplying r to the direction-vector-CP,
only the axis x,y,z will be scaled, but the diagonal
distance between C and P will not be r.

sphere

How do I move P_old along the line CP to P_new?

Best Answer

The new point is just $$C+\frac{r\cdot CP}{|CP|}$$