Sphere-line intersection

May 2008
87
0
I want to find the coordinates of where a line projected from inside a sphere intersects the inner surface of the sphere.

The sphere is: \(\displaystyle 4(x-2)^2 + 16(y-4)^2 + (z-5)^2 = 400\)
Eye point at: \(\displaystyle (13, -3.5, 29)^T\)
Viewing direction: \(\displaystyle (-2, 3, -16)^T\)

At what coordinates does the line from the eye point in direction of the viewing direction hit the surface of the sphere?
 

HallsofIvy

MHF Helper
Apr 2005
20,249
7,909
I want to find the coordinates of where a line projected from inside a sphere intersects the inner surface of the sphere.

The sphere is: \(\displaystyle 4(x-2)^2 + 16(y-4)^2 + (z-5)^2 = 400\)
Eye point at: \(\displaystyle (13, -3.5, 29)^T\)
Viewing direction: \(\displaystyle (-2, 3, -16)^T\)

At what coordinates does the line from the eye point in direction of the viewing direction hit the surface of the sphere?
A line, in three dimensions, that includes the point \(\displaystyle (x_0, y_0, z_0)\) and points in the direction of vector \(\displaystyle <A, B, C>\) can be written in parametric equations as \(\displaystyle x= At+ x_0\), \(\displaystyle y= Bt+ y_0\), and \(\displaystyle z= Ct+ z_0\). The line from the eye point, (13, -3.5, 29) in direction <-2, -3, -16> has equations \(\displaystyle x= -2t+ 13\), \(\displaystyle y= -3t- 3.5\), and \(\displaystyle z= -16t+ 29\).

Replace x, y, and z in the equation of the sphere with those and you get one quadratic equation for t. Solve for t, then use the parametric equations of the line to find the corresponding x, y, and z values.

A quadratic equation may have no real solution, one (double) solution, or two solutions. Those correspond to the cases where the line misses the sphere entirely, is tangent to the sphere, or crosses through the sphere.

Since the given point is inside the sphere, there will have to be two solutions, one with t negative and one with t positive. Since the parametric equations were set up with t multiplying the direction vector, the correct solution will be the one for the positive t.
 
  • Like
Reactions: posix_memalign
May 2008
87
0
A line, in three dimensions, that includes the point \(\displaystyle (x_0, y_0, z_0)\) and points in the direction of vector \(\displaystyle <A, B, C>\) can be written in parametric equations as \(\displaystyle x= At+ x_0\), \(\displaystyle y= Bt+ y_0\), and \(\displaystyle z= Ct+ z_0\). The line from the eye point, (13, -3.5, 29) in direction <-2, -3, -16> has equations \(\displaystyle x= -2t+ 13\), \(\displaystyle y= -3t- 3.5\), and \(\displaystyle z= -16t+ 29\).

Replace x, y, and z in the equation of the sphere with those and you get one quadratic equation for t. Solve for t, then use the parametric equations of the line to find the corresponding x, y, and z values.

A quadratic equation may have no real solution, one (double) solution, or two solutions. Those correspond to the cases where the line misses the sphere entirely, is tangent to the sphere, or crosses through the sphere.

Since the given point is inside the sphere, there will have to be two solutions, one with t negative and one with t positive. Since the parametric equations were set up with t multiplying the direction vector, the correct solution will be the one for the positive t.
Thanks!

I just tried your suggested solution but I got that t = 2.5 or t = 1.5 -- no negative t, I double checked my calculations, perhaps I still made some miscalculation or is it possible to get two positive t?
 

HallsofIvy

MHF Helper
Apr 2005
20,249
7,909
Well, you said "a line projected from inside a sphere" so I assumed that you meant that the eye point was inside. It's easy to see that it isn't: \(\displaystyle 4(13- 2)^2\) alone is larger than 400.

And, by the way, that is not a sphere- it is an ellipsoid.
 
May 2008
87
0
Well, you said "a line projected from inside a sphere" so I assumed that you meant that the eye point was inside. It's easy to see that it isn't: \(\displaystyle 4(13- 2)^2\) alone is larger than 400.

And, by the way, that is not a sphere- it is an ellipsoid.
Ah, I see, sorry for my mistake.

However does t = 1.5 and t = 2.5 mean that the line intersects the ellipsoid first once on the surface, and then once again from the inside and out (after having passed through the inside of the ellipsoid)?
 

HallsofIvy

MHF Helper
Apr 2005
20,249
7,909
Well, if then the line is projected from inside the sphere to the eyepoint, the point at which it strikes the surface is the point closer to the eyepoint.