Maths used by Vrml Viewpoints

First, the program finds the x, y and z components of the vector for the desired direction of view, re-scaled to be of length 1. These are known as the direction cosines of a vector.

Next it needs to find the transformation to apply to the vector of the default viewpoint, to turn it to the direction of the new vector.

First it finds the angle to turn about x to move the y coordinate to the correct position.

Then it finds the angle to turn about y to move the x and z coordinates to the correct position. All three coordinates are now in the correct position.

If the tilt is non zero, this needs to be added as a third rotation.

It now finds the matrix for the combination of all the rotations, by finding the matrix for each one, and multiplying them together using matrix multiplication. When rotations are multiplied in this way, the result is always a new rotation.

Now that it's got the matrix for the desired rotation, it has to use this to find its axis and angle of rotation.

It can find the axis, since this is left unchanged when the rotation is applied. So it can find the axis v as a solution of the equation R.v=v where R is the new matrix.

Another way of stating this equation is (R-I).v=0, where I is the identity matrix, and so R-I is the result of subtracting 1 from the three diagonal elements of R.

To solve this, it needs to solve a set of three simultaneous equations. It does this by Gaussian elimination, i.e. eliminating one variable at a time.

Finally it has to find the angle of rotation about the new axis needed to map the vector to the new position. It can do this by using the formulae for a matrix for a rotation by an arbitrary angle about the new axis, and solving to find the particular angle needed.