# Math Help - Sphere-line intersection

1. ## Sphere-line intersection

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: $4(x-2)^2 + 16(y-4)^2 + (z-5)^2 = 400$
Eye point at: $(13, -3.5, 29)^T$
Viewing direction: $(-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?

2. Originally Posted by posix_memalign
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: $4(x-2)^2 + 16(y-4)^2 + (z-5)^2 = 400$
Eye point at: $(13, -3.5, 29)^T$
Viewing direction: $(-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 $(x_0, y_0, z_0)$ and points in the direction of vector $$ can be written in parametric equations as $x= At+ x_0$, $y= Bt+ y_0$, and $z= Ct+ z_0$. The line from the eye point, (13, -3.5, 29) in direction <-2, -3, -16> has equations $x= -2t+ 13$, $y= -3t- 3.5$, and $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.

3. Originally Posted by HallsofIvy
A line, in three dimensions, that includes the point $(x_0, y_0, z_0)$ and points in the direction of vector $$ can be written in parametric equations as $x= At+ x_0$, $y= Bt+ y_0$, and $z= Ct+ z_0$. The line from the eye point, (13, -3.5, 29) in direction <-2, -3, -16> has equations $x= -2t+ 13$, $y= -3t- 3.5$, and $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?

4. 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: $4(13- 2)^2$ alone is larger than 400.

And, by the way, that is not a sphere- it is an ellipsoid.

5. Originally Posted by HallsofIvy
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: $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)?

6. 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.