How do i compute the closest points on a sphere given a point outside the sphere?

788 Views Asked by At

I looking for method which can compute the yellow area in this image..

enter image description here

The ball with the green fill is a sphere, where i know the center point and the radius of it. The circle with the red fill outside i a point outside the sphere.

How do find the point which is closest to the points, and some points around around the closest point (indicated by the yellow marking)?

2

There are 2 best solutions below

1
On

Let's say your sphere has radius $R$ and center $(a,b,c)$. Your point is $(A,B,C)$.

The distance $D$ from the point to the center of the sphere is

$$D = \sqrt{(A-a)^2 + (B-b)^2 + (C-c)^2}.$$

A unit vector from the center of the sphere, toward your point, is

$$\left(\frac{A-a}{D}, \frac{B-b}{D}, \frac{C-c}{D}\right).$$

Then, to reach the point on the sphere closest to your point, start at the center, and go in the direction of the vector a distance $R$:

$$P = \left(a + R\left(\frac{A-a}{D}\right), b + R\left(\frac{B-b}{D}\right), c + R \left(\frac{C-c}{D}\right)\right).$$

0
On

I will do this using vectors, so the number of dimensions does not matter.

If the sphere has center $A = (a_1, ..., a_n)$ and radius $r$, and the point is $P=(p_1, ..., p_n)$, the line from $P$ to $A$ is $L(t): P + t(A-P), 0 \le t \le 1 $.

This line intersects the sphere when $|L(t)| = r$ or, if $D = A-P$,

$\begin{array}\\ r^2 &=|P + tD|^2\\ &=(P + tD)\cdot(P + tD)\\ &=|P|^2+2tP\cdot D +t^2|D|^2\\ \end{array} $

or $t^2|D|^2+2tP\cdot D+|P|^2-r^2 = 0 $.

Note that we expect a quadratic, since the line intersects the sphere in two points, the closest and farthest.

Solving, we get $t =\dfrac{-2P\cdot D\pm \sqrt{d}}{2|D|^2} $ where $d =(2P\cdot D)^2-4|D|^2(|P|^2-r^2) =4((P\cdot D)^2-|D|^2(|P|^2-r^2)) $ so

$\begin{array}\\ t &= \dfrac{-2P\cdot D\pm \sqrt{d}}{2|D|^2}\\ &= \dfrac{-2P\cdot D\pm \sqrt{4((P\cdot D)^2-|D|^2(|P|^2-r^2))}}{2|D|^2}\\ &= \dfrac{-P\cdot D\pm \sqrt{(P\cdot D)^2-|D|^2(|P|^2-r^2)}}{|D|^2}\\ &= \dfrac{-P\cdot D^*\pm \sqrt{(P\cdot D^*)^2-(|P|^2-r^2)}}{|D|} \qquad\text{where }D^* = D/|D|\\ \end{array} $

The points of intersection of the line with the sphere are

$\begin{array}\\ L(t) &=P+Dt\\ &=P+D\dfrac{-P\cdot D^*\pm \sqrt{(P\cdot D^*)^2-(|P|^2-r^2)}}{|D|}\\ &=P+D^*(-P\cdot D^*\pm \sqrt{(P\cdot D^*)^2-(|P|^2-r^2)})\\ \end{array} $

To get the intersection you want, choose the one with $0 \le t \le 1$.

I will leave the problem of find the circle on the sphere to others. The method will vary depending on whether the circle is specified by its distance from the intersection point, the angle the circle subtends from the center of the sphere, or some other criterion.