0
$\begingroup$

Here is a picture of my situation for tangent length (pardon the fact that the line in the picture isn't actually tangent visually, just pretend it is) enter image description here

Here is a picture of the secant line I'm trying to get.enter image description here

So here's my situation, I have a sphere, and a ray. I want to find the secant length of that ray through the sphere. I have the length of the ray up until it hits the surface of the sphere, and I have the origin of the ray and the sphere. I was going to use the plane of the sphere origin and the point on the sphere to do a calculation of secant on a circle. In order to find the secant length I was going to use this formula:

$tangentLength^2 = lengthToCircle *(secantLength + lengthToCircle)$

So I needed to find out how to get the tangent length. Using the first image in this post, and this stack overflow answer I set out to find the tangent length. I used primarily these formulas:

$a = asin( \frac{radius}{distance} )$

$b = atan2(dy, dx)$

$theta = b - a $

The theta should correspond to the $\theta_1$ in the first picture

I figured that it didn't matter where, in terms of angle, where I was oriented on the circle, since I only cared about length, so I was able to say that my $p1 = (0, distance)$ where $distance$ is the distance from the point to the center of the sphere in 3d space.

Given this, $b = \pi/2$ since $atan2(x, 0.0) = \pi/2$.

So $\theta_1$ now became $\pi/2 - asin( \frac{radius}{distance} ))$

So now that I know I have theta I can figure out $\theta_2$ from the first picture.

$\theta_2 = \pi - \pi/2 - \theta_1$

and using law of sines I can say in the picture that:

$\frac{radius}{\sin(\theta_1)} = \frac{tangentLength}{\sin(\phi_1)} = \frac{distance}{\sin(\theta_1 + \phi_2)}$

so I need $\phi_1$. in order to get $\phi_1$ I solve for $\phi_2$.

$\phi_2 = asin(\frac{distance}{radius} * sin(\theta_1)) - \theta_2$

then I find $\phi_1$ through:

$\phi_1 = \pi - \pi / 2 - \phi_2$

and solve for the $tangentLength$ via

$tangentLength = \frac{radius}{sin(\theta_1)} * sin(\phi_1)$

and finally solve for the secant length using the first equation I mentioned. This however is giving odd results. At certain distance away from the sphere, tangent length appears to simply become zero, and the secant length appears to decrease in a way I would not expect with certain small distance increments away from the sphere. I'm seeing this behavior in the order of magnitude of hundreds of units a way from a sphere whose radius is 90.

$\endgroup$
  • 1
    $\begingroup$ Did you know that the tangent is perpendicular to the radius? So $tangent=\sqrt{DistanceBetweenOrigins^2-radius^2}$ $\endgroup$ – Vasya Mar 14 '18 at 15:08
  • $\begingroup$ @Vasya You know some one else mentioned that formula in the other SO thread and I didn't understand what they were saying, but this makes so much more sense, the way I drew tangent (as can be clearly seen here) made me miss this fact. That solved my actual problem as well. I'm not going to get rid of this question though, because my original way should also work, which means I'm not understanding something about this more complicated process. $\endgroup$ – opa Mar 14 '18 at 15:17
  • 1
    $\begingroup$ your math is also correct, just note that $sin(\phi_1)=sin(\pi/2-\theta_1)=cos(\theta_1)$ so $tangentLength = radius \cdot \tan(\theta_1)$ $\endgroup$ – Vasya Mar 14 '18 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.