3

This is a simple question, but my geometry is a little rusty.

If I have two points that lie outside of a sphere in 3D space, and I am given the X, Y, and Z coordinates for them, how do I determine if the line that intercepts those points is intercepted by a sphere with a center at the origin and a given radius r?

Thanks!

KReiser
  • 65,137
Julia
  • 31

5 Answers5

3

The line segment $pq$ can be described vectorially by

$$p+t\,\vec{pq}$$ where $t\in[0,1]$.

The segment intersects the sphere of center $c$ and radius $r$ if for some $t$,

$$\|\vec{cp}+t\,\vec{pq}\|^2=r^2,$$ or

$$\vec{pq}^2t^2+2\,\vec{pq}\,\vec{cp}\,t+\vec{cp}^2-r^2=0.$$

This is a quadratic equation in $t$. If it has real roots, check if the interval they define overlaps with $[0,1]$.

1

You have the points $A,B$ at the two ends of the segment and the center $C$ of the sphere.
The three points lie on a plane.
You already know that $A,B$ are external to the sphere, which anyway is a condition not difficult to check.

Call $$ {\bf b} = {{\mathop {AB}\limits^ \to } \over {\left| {AB} \right|}} $$ the unit vector parallel to the segment.

Then for the segment to cross the sphere, we shall have that the distance of $ C$ from the segment be less than the radius of the sphere and that the projection of $C$ on the segment be internal to it, i.e. $$ \left\{ \matrix{ {\rm distance}\,{\rm of}\;{\rm C}\,{\rm from}\,{\rm segment:}\;\left| {\mathop {AC\;}\limits^ \to \times \;{\bf b}} \right| < r \hfill \cr {\rm projection}\,{\rm of}\;{\rm C}\,{\rm on the segment:}\;0 \le \mathop {AC\;}\limits^ \to \; \cdot {\bf b} \le \left| {AB} \right| \hfill \cr} \right. $$

G Cab
  • 35,272
1

Let $C$ be the sphere’s center, $P$ and $Q$ the endpoints of the segment and $r$ the radius of the sphere. For the segment to intersect the sphere, the distance of its extension to $C$ must be $\le r$ and the endpoint must not lie on the same side of the perpendicular plane through $C$. Using a standard formula, the first condition translates into $${\lVert(Q-P)\times(P-C)\rVert^2\over \lVert Q-P\rVert^2}\le r^2$$ and for the second, the signs of $(Q-P)\cdot(Q-C)$ and $(Q-P)\cdot(P-C)$ must be different.

amd
  • 53,693
0

As Trelzevir wrote, the simple method is finding a point $P$ on the given line $AB$, closest to the sphere's centre $O$. Then you need to find if $OP$ distance is less than (or equal to) the radius of a sphere and if $P$ is between $A$ and $B$. If both condtions are satisfied, the segment crosses the sphere (or touches it in case of equality).

CiaPan
  • 13,049
0

Let the two points be $A$ and $B$, with respective position vectors $\pmb a$ and $\pmb b$ from the origin $O$. Consider the triangle $AOB$, with $\angle AOB=\theta$. Let $h$ be the distance from $O$ to the line $AB$. Then the area of $\triangle AOB$ is $\frac12|\pmb a||\pmb b|\sin\theta$, which is $\frac12|\pmb a\times\pmb b|$, or equally $\frac12h|\pmb a-\pmb b|$. Thus$$|\pmb a\times\pmb b|=h|\pmb a-\pmb b|.$$The condition for the line $AB$ to intercept a sphere of radius $r$ centered at the origin is $h\leqslant r$, or$$|\pmb a\times\pmb b|\leqslant r|\pmb a-\pmb b|.$$

John Bentin
  • 18,454