Lets say, you have a sphere centered at x0,y0,z0
with radius a and a line passing through x1,y1,z1
and x2,y2,z2
. Then you can use Solve
{x0, y0, z0} = {0, 1, 0}
r = 2
{x1, y1, z1} = {0, 0, 0}
{x2, y2, z2} = {2, 1, 1}
intsct = {x, y, z} /. Solve[{x, y, z} ∈ InfiniteLine[{{x1, y1, z1}, {x2, y2, z2}}]
&& {x, y, z} ∈ Sphere[{x0, y0, z0}, r], {x, y, z}]
$\{\{\frac{1}{3}\text{ (1-}\sqrt{19}\text{),}\frac{1}{6}\text{
(1-}\sqrt{19}\text{),}\frac{1}{6}\text{
(1-}\sqrt{19}\text{)$\}$,$\{$}\frac{1}{3}\text{
(1+}\sqrt{19}\text{),}\frac{1}{6}\text{
(1+}\sqrt{19}\text{),}\frac{1}{6}\text{ (1+}\sqrt{19}\text{)$\}\}$}$
EuclideanDistance[intsct[[1]], intsct[[2]]]//N
3.55903
Graphics3D[{InfiniteLine[{{x1, y1, z1}, {x2, y2, z2}}],
PointSize[Large], Point[intsct], Opacity[0.5], Sphere[{x0, y0, z0}, r]}]
