# Distance between point a and intersection of a sphere

• October 12th 2012, 12:43 AM
VortexFx
Distance between point a and intersection of a sphere
Hi all,

Not even sure this is in the right category applogies if it isnt.
Just wondered if someone could help me with an issue that i cannot seem to figure out below is an image excuse how crude it is, but i think it explains what im trying to do.

Attachment 25185

Im trying to get the distance from point A to entry point of the "circle/sphere" designated B i also want to get the distance from point A to the exit point of the "circle/sphere" designated B on both paths to C and D.

The Radius of "circle/sphere" B = 162

Total distance from A to B is 326
Total distance from A to C = 461
Total distance from A to D = 621

X,Y,Z coord are as shown on image.

Hope this is enough information for anybody willing to help me out.

If someone could explain how to do this in as simple terms as possible i would be very greatfull.
Im not that great at maths but im keen to learn.

• October 12th 2012, 06:13 PM
johnsomeone
Re: Distance between point a and intersection of a sphere
What you have is a line intersecting a circle (or sphere in 3 dimensions). A point of intersection (x,y) is both on the line and on the circle, so satisfies the equation for both. You end up with a non-linear system of 2 equations (one quadratic, one linear) in two unknowns (x and y). Solving that system gives you your points of intersection:

Circle: $(x-405)^2 + (y-216)^2 = 162^2$

Line AC: line through (100, 100) and (461, 53):

slope = $\frac{100-53}{100-461} = -\frac{47}{361}$, so it's $y-100 = -\frac{47}{361} (x - 100)$, so

$y = -\frac{47}{361} (x - 100) + 100 = -\frac{47}{361} x + \frac{4700}{361} + \frac{36100}{361} = -\frac{47}{361} x + \frac{40800}{361}$

System of equations is:

$(x-405)^2 + (y-216)^2 = 162^2$ and $y = -\frac{47}{361} x + \frac{40800}{361}$.

Plug the expression for y given by the 2nd equation into the first equation, and, after expanding and then collecting like terms, it becomes a quadratic equation for x, which has two solutions (hopefully - according to the picture). For each solution for x, use the second equation to find the value of y. This is how you find the two points of intersection (x,y).
• October 15th 2012, 12:57 AM
VortexFx
Re: Distance between point a and intersection of a sphere
Thanks for the reply, how would i add the third dimension into this equasion?
• October 15th 2012, 11:43 AM
johnsomeone
Re: Distance between point a and intersection of a sphere
z = 100 for all the points in question, so z=100 is the z coordinate of the solution. It's all takeing place in the plane z=100.

In general, given a line in 3 space and a 2-dimensional sphere in 3 space, you'd probably want to describe the line parametrically (although vector notation is cleaner, it's also less "algebraic" and might seem confusing), and then solve for that parameter to get the points of intersection:

Line: $x(t) = a_xt+b_x, y(t) = a_yt + b_y, z(t) = a_zt + b_z$

Sphere: $(x - c_x)^2 + (y-c_y)^2 + (z - c_z)^2 = R^2$.

So substitute, expland, collect like terms, and then solve for t:

Substitute:

$((a_xt+b_x) - c_x)^2 + ((a_yt+b_y)-c_y)^2 + ((a_xt+b_x) - c_z)^2 = R^2$.

Expand:

$[a_x^2t^2 + 2(a_x)(b_x - c_x)t +(b_x - c_x)^2]$

$+ [a_y^2t^2 + 2(a_y)(b_y - c_y)t +(b_y - c_y)^2]$

$+ [a_z^2t^2 + 2(a_z)(b_z - c_z)t +(b_z - c_z)^2]$

$= R^2$.

Collect like terms:

$[a_x^2 + a_y^2 + a_z^2] \ t^2$

$+ 2[a_x(b_x - c_x) + a_y(b_y - c_y) + a_z(b_z - c_z)] \ t$

$+[(b_x - c_x)^2 + (b_y - c_y)^2 + (b_z - c_z)^2 - R^2]$

$= 0$

Solve:

$t = \frac{-2[a_x(b_x - c_x) + a_y(b_y - c_y) + a_z(b_z - c_z)] \pm \sqrt{4D}}{2(a_x^2 + a_y^2 + a_z^2)}$, where

$4D = (2[a_x(b_x - c_x) + a_y(b_y - c_y) + a_z(b_z - c_z)])^2$

$- 4(a_x^2 + a_y^2 + a_z^2)((b_x - c_x)^2$

$+ (b_y - c_y)^2 + (b_z - c_z)^2)$.

Simplifying a bit:

$t = \frac{-[a_x(b_x - c_x) + a_y(b_y - c_y) + a_z(b_z - c_z)] \pm \sqrt{D}}{a_x^2 + a_y^2 + a_z^2}$, where

$D = (a_x(b_x - c_x) + a_y(b_y - c_y) + a_z(b_z - c_z))^2$

$- (a_x^2 + a_y^2 + a_z^2)[(b_x - c_x)^2 + (b_y - c_y)^2 + (b_z - c_z)^2]$.
• October 16th 2012, 07:58 AM
johnsomeone
Re: Distance between point a and intersection of a sphere
That has a mistake. If you look at those equations for D, I left out the $-R^2$.