☖ Home Units Converter Geometry Σ Math Physics Electricity

Intersection of a line and a sphere calculator

Print Intersection of a line and a sphere
Parametric
line equation
L1:
x = 
 +
 t 
y = 
 +
 t 
z = 
 +
 t 
classic
line equation
L1:
x
=
y
=
z
Line defined
by 2 points
L1:
x1
y1
z1
x2
y2
z2
Line defined
by vector
L1:
Vector:
i
 +
  j
 +
  k
Point:
x:
y:
z:
Sphere of the form:     (x − a)2 + (y − b)2 + (z − c)2 = r2
(x
 
)2 + (y
 
)2 + (z
 
)2 =
 
 2
Sphere of the form:     x2 + y2 + z2 + Ax + By + Cz + D = 0
x2 + y2 + z2
 +
 x
 +
 y
 +
 z
 +
= 0
First intersection point:
 
Second intersection point:
 
Distance between intersections:
 
Distance of line to sphere center:
 
     

Sphere and line intersection summary

Print sphere intersection summary

Parametric equation of a line given by two points along the line (x1 , 2 , y1 , 2, z1 , 2) is:

x = x1 + (x2 − x1)t
y = y1 + (y2 − y1)t
z = z1 + (z2 − z1)t

Sphere equation:

(x − xc)2 +(y − yc)2 + (z − zc)2 = r2
Substituting line values x, y and z into the equation of the sphere gives a quadratic equation of the form:    at2 + bt + c = 0    Where a, b and c are equal to: (for more information see example)
a = (x2 − x1)2 + (y2 − y1)2 + (z2 − z1)2
b = − 2[(x2 − x1)(xc − x1) + (y2 − y1)(yc − y1) + (zc − z1)(z2 − z1)]
c = (xc − x1)2 + (yc − y1)2 + (zc − z1)2 − r2
The solution for  t  is: t=(-b±√(b^2-4ac))/2a
Condition for intersection: b2 − 4ac > 0
Condition for tangency: b2 − 4ac = 0
No intersection when: b2 − 4ac < 0
The intersection points can be calculated by substituting  t  into the parametric line equations.

Note: if the incline of the line is known then the parametric line equations are:

x = x1 + (x2 − x1)t
x = x1 + xtt
y = y1 + (y2 − y1)t
y = y1 + ytt
z = z1 + (z2 − z1)t
z = z1 + ztt

And the values of the coefficients a, b and c of the quadratic equation   at2 + bt + c = 0,   will give us as found before, the values of  t , that when substituting it in the line parametric equation will give us the two intersection points.

a = xt2 + yt2 + zt2
b = − 2[xt(xc − x1) + yt(yc − y1) + zt(zc − z1)]
c = (xc − x1)2 + (yc − y1)2 + (zc − z1)2 − r2

Example 1 − Sphere and line intersection

Print sphere intersection summary
Find the intersection points of the sphere     (x + 1)2 ⧾ (y + 4)2 z2 = 16
with the line given by    x = 1 ⧾ t,       y = 2,       z = 3 − 2t
Two arbitrary points on the line can be found by substituting t = 0 and t = 1

For t = 0 {x1 = 1 + t = 1,       y1 = 2, and       z1 = 3 − 2*0 = 3}   point x1, y1, z1  is at:   (1 , 2 , 3)

For t = 1 {x2 = 1 + t = 2,       y2 = 2, and       z2 = 3 − 2*1 = 2}   point x2, y2, z2  is at:   (2 , 2 , 2)

The center of the sphere is at {xc , yc , zc} = {−1 , −4 , 0}

First find the values of the coefficients  a, b  and  c:
a = (1)2 ⧾ (0)2 ⧾ (− 2)2 = 5
b = − 2[(1)(1 − 1) ⧾ (0)(4 − 2) ⧾ (− 2)(0 − 3)] = − 12
c = (1 − 1)2 ⧾ (4 − 2)2 ⧾ (0 − 3)2 − 16 = − 3
The quadratic equation is: 5t212t − 3 = 0
x1 = 1 ⧾ 2.63 = 3.63
y1 = 2
z1 = 3 − 2 • 2.63 = − 2.26
x2 = 1 − 0.23 = 0.77
y2 = 2
z2 = 3 ⧾ 2 • 0.23 = 3.46
And the intersection points are at:
(3.63, 2, − 2.26)
and
(0.77, 2, 3.46)

Example 2 − Sphere and line detail equations solution

Print sphere equation
Find the intersection points of the parametric line given by the equations:
x = x1 + (x2 − x1)t
y = y1 + (y2 − y1)t
z = z1 + (z2 − z1)t
and the sphere given by the equation:   (x − xc)2 +(y − yc)2 + (z − zc)2 = r2
Because the intersection points of the parametric equations should satisfy the sphere equation, we will substitute the values of  x y  and  z  of the parametric equations into the sphere equation:
[(x2 − x1)t − (xc − x1)]2 ⧾ [(y2 − y1)t − (yc − y1)]2 [(z2 − z1)t − (zc − z1)]2 = r2
Now we will find the square values of the parenthesis.
(x2 − x1)2t2 − 2t(x2 − x1)(xc − x1) + (xc − x1)2 + (y2 − y1)2t2 − 2t(y2 − y1)(yc − y1) +
(
yc − y1)2 + (z2 − z1)2t2 − 2t(z2 − z1)(zc − z1) + (zc − z1)2 − r2 = 0
Arranging the expression received as a powers of  t  we get:
t2[(x2 − x1)2 + (y2 − y1)2 + (z2 − z1)2]
2t[(x2 − x1)(xc − x1) + (y2 − y1)(yc − y1) + (z2 − z1)(zc − z1)] +
(xc − x1)2 + (yc − y1)2 + (zc − z1)2 − r2 = 0
And we got a quadratic equation of the form:       at2 + bt + c = 0
Where: a = (x2 − x1)2 + (y2 − y1)2 + (z2 − z1)2
b = − 2[(x2 − x1)(xc − x1) + (y2 − y1)(yc − y1) + (z2 − z1)(zc − z1)]
c = (xc − x1)2 + (yc − y1)2 + (zc − z1)2 − r2
The solution for  t  is: t=(-b±√(b^2-4ac))/2a
Substitute these values of  t  into the parametric line equations to get the intersection points.

Example 2a − Sphere and line detail equations solution

Print sphere equation
Find the intersection points of the parametric line given by the equations:
x = x1 + xtt
y = y1 + ytt
z = z1 + ztt
and the sphere given by the equation:
  (x − xc)2 +(y − yc)2 + (z − zc)2 = r2
Because the intersection points of the parametric equations should satisfy the sphere equation, we will substitute the values of  x y  and  z  of the parametric equations into the sphere equation:
(x1 + xtt − xc)2(y1 + ytt − yc)2(z1 + ztt − zc)2 = r2
[(x1 − xc) + xtt]2[(y1 − yc) + ytt]2[(z1 − zc) + ztt]2 = r2
Now we will find the square values of the parenthesis.
(x1 − xc)2 + 2 (x1 − xc)xtt + xt2t2 + (y1 − yc)2 + 2 (y1 − yc)ytt + yt2t2 + (z1 − zc)2 + 2 (z1 − zc)ztt + zt2t2 − r2 = 0
Arranging the expression received as a powers of  t  we get:
(xt2 + yt2 + zt2) t2 +
2 [(x1 − xc) xt + (y1 − yc) yt + (z1 − zc) zt] t +
(x1 − xc)2 + (y1 − yc)2 + (z1 − zc)2 − r2 = 0
And we got a quadratic equation of the form:       at2 + bt + c = 0
Where:
a = (xt2 + yt2 + zt2)
b = 2 [(x1 − xc) xt + (y1 − yc) yt + (z1 − zc) zt]
c = (x1 − xc)2 + (y1 − yc)2 + (z1 − zc)2 − r2
The solution for  t  is:
t=(-b±√(b^2-4ac))/2a
Substitute these values of  t  into the parametric line equations to get the intersection points.

Example 3 − Sphere radius

Print sphere radius
Find the radius of the sphere given by the equation x2 + y2 + z2 − 8x + 4y + 6z + 20 = 0.

Set the given sphere equation into groups as follows:

( x2 − 8x +        ) + ( y2 + 4y +        ) + ( z2 + 6z +        ) + 20 = 0

Notice that:

(x2 − 8x) = (x − 4)2 − 16

(y2 + 4y) = (y + 2)2 − 4

(z2 + 6z) = (z + 3)2 − 9

Substituting these values into the equation of the sphere to get:

(x − 4)2 − 16 + (y + 2)2 − 4 + (z + 3)2 − 9 + 20 = 0

After arranging the terms of the equation, we have:

(x − 4)2 + (y + 2)2 + (z + 3)2 − 16 − 4 − 9 + 20 = 0

(x − 4)2 + (y + 2)2 + (z + 3)2 − 9 = 0

From this sphere equation it is obvious that the center of the sphere is at   (4 , −2 , −3)   and

the radius of the sphere is: r = 3.