Quat (EX angle, VE #3 direction)

            We use the unit quaternions to represent rotations in Mathscript, because that makes it easy to work with them algebraically.  In fact, Mathscript has a built-in quaternion number type. 

quat(angle, [n1,n2,n3]);

represents the rotation about the vector [n1,n2,n3]  (which is automatically normalized) through angle degrees, using the right-hand rule to determine the sense

Each 4-vector of reals represents a quaternion as follows:

[t, u, v, w ] is interpreted as:  t*1 + u*i + v*j + w*k.

These may be multiplied, divided, added and subtracted directly.  Thus if you say:

make a [0,1,0,0];

make b [0,0,1,0];

and then type at the command line:

print a*b; 

you will see [0,0,0,1]

if you type:

print a/b;

you will see [0,0,0,-1]

            The unit quaternions (t^2+u^2+v^2+w^2 = 1)  form a group, and there are precisely two unit quaternions for each rotation of space.  Multiplication of unit quaternions corresponds to composition of their rotations.

            A unit quaternion is given by the Quat function whenever we supply an angle t (measured in degrees) and a unit (length-1) 3-vector N.  So Quat( t, N ) is one of the two quaternions that represents the rotation about the unit vector N through t degrees, where the rotation is calculated using the right-hand rule: point your right thumb in the N direction, and the fingers curl in the direction of turning.  If you supply a vector for N which is not normalized, Mathscript normalizes it for you.

If we say, for example:

Make a quat(30, [1,0,0]);

Make b quat (30, [0,1,0]);

then a represents a rotation of 30 degrees about the x-axis, using the right hand rule.  And b represents a 30-degree rotation about the y-axis.  And a*b represents the rotation obtained by doing a first, and b next.

Notice that a*b is not the same as b*a.