Having the values (x1 y1 z1), Based on the figure below, I need to find the (x2 y2 z2)
O1 ={0 0 0} r1 = R1
O2 = {0 0 L} r2 = R2
Having the values (x1 y1 z1), Based on the figure below, I need to find the (x2 y2 z2)
O1 ={0 0 0} r1 = R1
O2 = {0 0 L} r2 = R2
On
Let $P_2 = (x_1, y_1, z_1)$ be the intersection of the given ray with the sphere centered at $O_2.$ Construct a triangle $\triangle O_1 O_2 P_2.$ Let angle $\theta = \angle O_2 O_1 P_2$; this is the angle between the ray and the positive $z$ axis.
Consider the triangle formed by the points $O_1 = (0,0,0),$ $(x_1,y_1,z_1),$ and $(0,0,z_1).$ This is a right triangle with the same angle $\theta$ at $O_1.$ From this right triangle, by examining the ratio of the hypotenuse to the leg along the $z$ axis we find that $\cos\theta = z_1/R_1.$
Applying the cosine law to triangle $\triangle O_1 O_2 P_2,$ we have $$ R_2^2 = L^2 + r^2 - 2\cos\theta Lr. $$
Substitute $z_1/R_1$ for $\cos\theta$ and rearrange the terms to make this a quadratic equation over $r$: $$ r^2 - 2\frac{z_1}{R_1} Lr + L^2 - R_2^2 = 0. $$
This can be solved by the usual formula for roots of quadratic equations: \begin{align} r &= \frac12 \left(2\frac{z_1}{R_1} L \pm \sqrt{\left(2\frac{z_1}{R_1} L\right)^2 - 4(L^2 - R_2^2)}\right)\\ &= \frac{z_1}{R_1} L \pm \sqrt{\left(\frac{z_1}{R_1} L\right)^2 - L^2 + R_2^2}. \end{align}
Now we want a point at distance $r$ from the origin in the same direction as $(x_1,y_1,z_1).$ That is, we want a point $r/R_1$ times as far from the origin as $(x_1,y_1,z_1).$ Based on the diagram, we want to take the positive value of the $\pm$ part in the formula above; the negative value will give us a "backward" projection to the point where the line from $(x_1,y_1,z_1)$ to $O_1$ intersects the smaller sphere on the other side of $O_1.$
So the final result is $(kx_1,ky_1,kz_1),$ where $$k = \frac1{R_1} \left(\frac{z_1}{R_1} L + \sqrt{\left(\frac{z_1}{R_1} L\right)^2 - L^2 + R_2^2}\right). $$
Given
$$ C_1\to ||P-O_1|| = R_1\\ C_2\to ||P-O_2|| = R_2\\ P_1 = (x_1,y_1,z_1) \in C_1 $$
with
$$ P = (x,y,z)\\ O_1 = (0,0,0)\\ O_2 = (0,0,L) $$
how to obtain $P_2 = (x_2,y_2,z_2) \in C_2$ such that $O_1, P_1$ and $P_2$ are aligned ?
Choosing the line
$$ L\to P = \lambda \vec v $$
with $ \vec v = P_1/R_1$ it's intersections with $C_2$ are obtained by solving for $\lambda$
$$ ||\lambda\vec v-O_2|| = R_2 $$
or squaring
$$ \lambda^2||\vec v||^2-2\lambda <\vec v, O_2 > + ||O_2||^2 = R_2^2 $$
or
$$ \lambda = \frac{< \vec v, O_2 > \pm\sqrt{ < \vec v, O_2 > ^2-||O_2||^2+R_2^2}}{||\vec v||} $$
but here $\vec v = P_1/R_1$ is an unit vector so
$$ \lambda = \frac{1}{R_1} < P_1, O_2 >\pm \sqrt{\frac{1}{R_1^2}< P_1,O_2>^2-||O_2||^2+R_2^2} $$
or
$$ \lambda = \frac{z_1 L}{R_1}\pm \sqrt{\frac{z_1^2 L^2}{R_1^2}-L^2+R_2^2} $$
and thus we can have solutions for $P_2$ as
$$ P_2 = \left(\frac{z_1 L}{R_1}\pm \sqrt{\frac{z_1^2 L^2}{R_1^2}-L^2+R_2^2}\right)\frac{P_1}{R_1} $$
NOTE
Here $< \cdot, \cdot > $ represents the scalar product of two vectors.