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)

Here is a picture of the secant line I'm trying to get.
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.