Point $A$ is located outside of a circle centered at $C$ and with radius $r$. Point $B$ is given point inside the circle. How to calculate $d$, the length of line segment between $B$ and circumference on the line $\overline{AB}$. Would there be a solution regardless of where $B$ is inside the circle?
Update: given to the problem is coordinates $A$, $B$ and $r$. I will need to extend the same problem to 3D geometry with a sphere and 3D coordinates. I would appreciate any help.

A method for you to use.
Yes there is always a solution. To find it you can do the following, where the centre of the circle is taken as the origin.
You can find the equation of the line $AB$ in the form $y=mx+c$.
Then the point $P(x,y)$ where the line crosses the circle satisfies the equation $$ x^2+(mx+c)^2=r^2.$$
Solve this equation for $x$ and then find $y$ from $y=mx+c$. There will be two points, choose the one on the same side of the circle as $A$.
Finally calculate the distance $BP$.