Stereographic Projection

By Xah Lee, 2006-07.
   Xah
   xah@xahlee.org
 ∑ http://xahlee.org/

Let there be a sphere of radius r sitting on the plane at the origin. Let the north pole be denoted N. For any point P in the plane with coordinate {p1,p2}, let there be a line passing N and P. Then, the line will intersect the sphere at some point Q.

Given a coordinate {p1,p2}, we want to find the coordinate {q1,q2,q3} on the sphere.

In this notebook, we derive this result.

The equation of a sphere sitting on origin with radius r is
x^2+y^2+(z-r)^2-r^2==0

The parametric formula for a line in the direction of P-N and passing N is:

({p1, p2, p3} - {n1, n2, n3}) t + {n1, n2, n3}

Rewrite this as:
x==n1+(-n1+p1) t
y==n2+(-n2+p2) t
z==n3+(-n3+p3) t

replace x,y,z in the sphere equation by these, and we get a quadratic equation in t.

x^2 + y^2 + (z - r)^2 - 
        r^2 /. {x -> n1 + (-n1 + p1) t,  
        y -> n2 + (-n2 + p2) t, 
        z -> n3 + (-n3 + p3) t}

solve for t

Solve[-(r^2) + (((n1 + (-n1 + p1) t))^2) + (((n2 + (-n2 + p2) t))^2) + (((n3 - r + (-n3 + p3) t))^2) == 0, t]

plug the solution back to the parametric formular for line, results in the formula that is the coordinates of points on the sphere that is the intersection of the sphere and the line, expressed in terms of n1,n2,n3 and p1,p2,p3.

({p1, p2, p3} - {n1, n2, n3}) t + {n1, n2, n3} /. %

Now, assume the point P lies in the plane, so p3==0, and assume N is the north pole of the sphere, so that n1==0, n2==0, n3==2 r, we have:

% //. {p3 -> 0, n1 -> 0, n2 -> 0, n3 -> 2 r, 
        r -> 1/2}

% /. {p1 -> 1, p2 -> 0}

In a single line, the above Mathematica computation can be written as the followings.

Here we let the sphere be more general, centered on {0,0,c3}. The point N we restrict to {0,0,n3}, and the point P we restrict to {p1,p2,0}.

line = ({p1, p2, 0} - {0, 0, n3}) t + {0, 0, n3};
sphere = x^2 + y^2 + (z - c3)^2 - r^2;
mysolution = (line /. # &)@(Solve[# == 0, 
                t] &)@(sphere /. 
              MapThread[Rule, {{x, y, z}, line}])

Discarding the first solution, since it's just the coordinates of the north pole. The second solution is then:
Suppose the sphere sits on the origin, and has radius 1/2, and the north pole is then {0,0,r}

mysolution //. {r -> 1/2, n3 -> 2 r, 
        c3 -> r}

Now we know the first solution is just the north pole. We discard the first solution.
If the sphere actually is centered on {0,0,0}, then we have

mysolution //. {r -> 1/2, n3 ->  r, c3 -> 0}