Equation for distance from a point outside a sphere to any point on its surface I have a point m outside a sphere. The sphere center is o and r is the radius of sphere. Distance from point m to o is l.
If we draw a line from m to any point on the surface of sphere, this line has a length. Minimum length is l - r and maximum length would be l + r.
I want the equation for distance from m to any point on the surface of sphere.
Also how to draw the graph of this equation (all possible distances)?

 A: The center of the circle is at o and its radius is $r$. So, any general point on the surface of the sphere is given by $\mathbf{p} = \mathbf{o} +r \mathbf{\hat{e}}$, where $\mathbf{\hat{e}}$ is the radial unit vector in spherical co-ordinates.
In Cartesian coordinates, 
$$\mathbf{\hat{r}} =\sin{\theta}\cos{\phi} \mathbf{\hat{i}} + \sin{\theta}\sin{\phi}\mathbf{\hat{j}} + \cos{\theta} \mathbf{\hat{j}}$$ where $\mathbf{\hat{i}},\mathbf{\hat{j}},\mathbf{\hat{k}}$ are unit vectors along X,Y,Z directions respectively.
So, what you are looking for is $dist(\mathbf{m,p})$
If you already know the point $\mathbf{p}$, just find out this distance.
In order to plot this function , just vary $\theta$ from $0$ to $180$ degrees and $\phi$ from $0$ to $360$ degrees to cover the whole circle and find out $dist(\mathbf{m,p})$ for all the points. Store the values in an array and plot them.
Let me know if you need code in MATLAB or some other language.
A: This is what I was looking for: distance = 

See plot here.
A: The real problem is how to describe the position of the point on the surface of the sphere, and @Xaqron has not said how he wants to do that. But consider the plane containing the three points $M$, $O$ (the center of the sphere), and the point $B$ on the surface. You see that it intersects the whole picture in a circle of radius $r$ centered at $O$, and containing $B$. Now consider the angle $\theta=\angle\,MOB$. The honorable Law of Cosines gives us the distance $d=\overline{MB}$ directly: $d^2=1+r^2-2r\cos\theta\,$. But until @Xaqron tells us how he will describe the point on the sphere, we really can’t go any further than this.
A: Can I Please have the Matlab code for your solution 
The center of the circle is at o and its radius is r. So, any general point on the surface of the sphere is given by p=o+re^, where e^ is the radial unit vector in spherical co-ordinates.
In Cartesian coordinates,
r^=sinθcosϕi^+sinθsinϕj^+cosθj^
where i^,j^,k^ are unit vectors along X,Y,Z directions respectively.
So, what you are looking for is dist(m,p) If you already know the point p, just find out this distance.
In order to plot this function , just vary θ from 0 to 180 degrees and ϕ from 0 to 360 degrees to cover the whole circle and find out dist(m,p) for all the points. Store the values in an array and plot them.
