Escolar Documentos
Profissional Documentos
Cultura Documentos
But first
Hierarchical Transformations
Traditional Animation
Master artists draw certain important keyframes in the animation Apprentices draw the multitude of frames inbetween these key-frames Called tweens
In Practice
On Computers:
Object has an initial configuration and a final configuration (often specified by the artist) Computer must figure out the intermediate configurations: interpolation
Orientation Interpolation:
Given two key-frame orientations, figure out an intermediate orientation at a certain point between them
Possible Solutions
Potential Solution #1:
Use Euler angles Interpolate between individual angles
Solution
Use quaternion interpolation Quaternions dont suffer from Gimbal lock Can be represented as 4 numbers instead of 9 of a 3x3 matrix Trivial conversion between angle/axis representation Easy interpolation between two quaternions is easy
Representation
Defined like complex numbers but with 4 coordinates
q[w,(x,y,z)] also written q[w,v] where v = (x,y,z) q = w + xi + yj + zk Here, w is real part, and (x,y,z) are imaginary parts Think of w as angle in an angle-axis representation Think of (x,y,z) as axis in an axis-angle representation
Representation
For a right-hand rotation of radians about unit vector v, quaternion is: q = (cos(/2); v sin(/2))
Note how the 3 imaginary coordinates are noted as a vector Only unit quaternions represent rotations
Such a quaternion describes a point on the 4D unit hypersphere
Quaternion Toolbox
Addition
q1 + q2 = [w1 + w2, v1 + v2]
Multiplication Magnitude
Normalisation
N(q) = q / | q |
Conjugate
q* = [w , -v]
Inverse
q-1 = q* / | q | 2
Unit quternion
q is unit if | q | = 1 and q-1 = q*
Identity
qIdentity = [1,(0,0,0)] for multiplication, qIdentity = [0,(0,0,0)] for addition
First Method
Rotate vector P angle around the unit axis R:
1. Form the quaternion representing the vector P q1 = (0,Px,Py,Pz) 1. Form the rotation quaternion from the axis R and angle q2 = (cos(/2),Rx sin(/2),Ry sin(/2),Rz sin(/2)) 3. The rotated vector is given by v entry of the quaternion: q3 = q2 q1 q2* q2 must be of unit magnitude for this to work properly
is the angle
Quaternion to Matrix
From quaternion to a 3x3 rotation matrix:
See: http://www.gamasutra.com/features/19980703/quaternions_01.htm P.s. This may not work for you if not, have a look on the web for other examples
Quaternion Lerp
Lerp: Linear intERPolation:
LERP(Q0,Q1,t) = Q0 + t(Q1-Q0)
Normalised Lerp
This time, do same as above but normalise the quaternion after the LERP:
Normalise(LERP(Q0,Q1,t))
Enter: Slerp
Spherical Linear intERPolation Dont interpolate along a straight line between Q0 and Q1 Instead, interpolate along the surface of the unit hyper-sphere
Slerp
Need to know , the shortest angle between the two quaternions Provides a smooth interpolation with a constant rate of change Can also do a spline interpolation along a sequence of quaternions for a smooth path of rotations
Usage
Not always the best choice
Quaternions are (as you will have noticed) hard to visualise If another method will do and is simpler, it will be a more appropriate choice
But
Extremely useful in many situations where other representations are awkward Easy to use in your own programs once you have a quaternion class
Be wary!
1. Recall, each 3D rotation has two quaternion representations: q and -q 2. As you do calculations on quaternions (as is the case with matrices) rounding errors build up
A resulting quaternion that looks on paper like it should be unit may not actually be unit at all Make sure to normalise quaternions to prevent problems Analogous to the way one can orthogonalise a matrix to prevent the same problems, but easier to do with quaternions