the following code comes from a file named trackball.c (http://scv.bu.edu/documentation/pres...gl/trackball.c)


What I'd like to know is the mathematical concept behind this function. Why are this two constants being used here and what does it mean "inside sphere" and "on hyperbola". I was not able to find any website explaining why this works. I can use this function and the trackball in my OpenGL app works but I don't know why and it drives me crazy ;]

Code:
/*
 * Project an x,y pair onto a sphere of radius r OR a hyperbolic sheet
 * if we are away from the center of the sphere.
 */
inline float
tb_project_to_sphere(float r, float x, float y)
{
    float d, t, z;

    d = sqrt(x*x + y*y);
	
    if (d < r * 0.70710678118654752440) 
    { 
	/* Inside sphere */
        z = sqrt(r*r - d*d);
    } 
    else
    {
	/* On hyperbola */
        t = r / 1.41421356237309504880;
        z = t*t / d;
    }
    return z;
}
(this function is used to find the z-coordinate on an imagined sphere from mouse coordinates to further calculate a quaternion rotation for the camera/scene)