Mathematical concept behind 3D-Trackball
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)
Re: Mathematical concept behind 3D-Trackball
0.707... is 0.5 * sqrt(2.) or sqrt(0.5)
1.42... is sqrt(2.)
Re: Mathematical concept behind 3D-Trackball
@D_Drmmr: that's clear to me...
but for example why do we take a hyperbola when d is greater then r * 0.707?
I don't remember such calculations from school... I wish I could do the same on a sheet of paper and get the same result but I don't know how, there must be some math-website that illustrates this projection of points on a sphere and how it works.
Re: Mathematical concept behind 3D-Trackball
After perusing that .c file, the comments especially, I get the impression that they are using a sphere-proper for generating the z-coordinate when the (x,y) is close to the center of the sphere, but use an arbitary function (hyperbola-based in this case), for a better "feel" when the (x,y) is farther from center.
This appears to be a user interface decision, rather than a mathematically proper one.
If you can track down the article mentioned in the code comments, it would give a more detailed explanation, I'm betting.
Code:
* Implemented by Gavin Bell, lots of ideas from Thant Tessman and
* the August '88 issue of Siggraph's "Computer Graphics," pp. 121-129