rotations in computer graphics

Upload: bushbarack

Post on 19-Feb-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/23/2019 Rotations in Computer Graphics

    1/36

    4 Rotations

    The space of rotations has great importance in Computer Graphics. Examples of appli-

    cations include animation of rigid bodies, linked hierarchies, as well as the specification

    of external parameters for orientation and position of the virtual camera:In this chapter, we are interested on two problems:

    to obtain good representations and parameterizations of the space of rota-tions.

    In general, a good representation leads to a good parameterization. The latter, in turn,

    leads to good interface solutions for the user to specify and to manipulate rotations in the

    computer:

    Rotation Representation Parameterization Specification

    What is a good representation or a good parameterization as shown above? Current

    literature presents six methodologies to describe and to specify rotations in Computer

    Graphics: Interpolation (e.g. keyframes in animation); Direct and inverse kinematics;

    Direct and inverse dynamics and Space-time optimization.

    A good representation of the space of rotations should attend the requirements of these

    several methodologies. Among them we can mention:

    1. Capability of determining orientations of rigid bodies in space as a function of the

    parameters;

    2. The possibility to calculate the parameters from a rotation;

    3. The possibility to calculate the physical magnitudes of Kinematics and of the

    Dynamics associated with a rigid body.

    4. In particular, the previous item demands the possibility to (1) do calculations de-

    rived from the positions and orientations as a function of the parameters, (2) to

    obtain equations of several types (differential, integral, etc.) and (3) to solve those

    equations.

    1

  • 7/23/2019 Rotations in Computer Graphics

    2/36

    2 CHAPTER 4: ROTATIONS

    5. Possibility to have a good control in the interpolation of rotations, by means of theinterpolation of the associated parameters;

    6. The possibility to do operations among rotations either in the parameters or the

    representation space.

    We begin our study with a brief discussion about rotations on the plane.

    1 Rotations in the Euclidean Plane

    The space of rotations in the plane is indicated by SO(2)and it is called two-dimensionalspecial orthogonal group. Given an orthonormal basis =

    {b1, b2

    }of the plane, the

    rotationR that carries the canonical basis{e1, e2} to basisis defined by the angle between vectorse1 and b1, as shown in Figure 1(a). The matrix ofR is given by

    R() =

    cos sin sin cos

    . (4.1)

    Therefore, we have a natural parameterization ofR : RSO(2),R = R(). How-ever, the parameterization is not injective because R() = R(+ 2k). We can havebijectivity by restricting the domain to the interval[0, 2).

    Instead of using matrices, we can represent the spaceSO(2)using complex numbers.In fact, given an arbitrary point p = (x, y)of the plane, we identify p with the complex

    numberx+iy. We can then writep in its polar form,

    p= reip =r cos p+ri sin p,

    wherer =

    x2 +y2 is thenorm ofp, andp = arctg(y/x) is the angle from p withthex-axis (see Figure 1 (b)). Whenr = 1, we say the complex number is unit. In this

    e

    e

    b

    b

    (a)

    x

    y

    (b)

    Figure 1. Rotation of the plane (a); complex number (b).

  • 7/23/2019 Rotations in Computer Graphics

    3/36

    SECTION 1: ROTATIONS IN THE EUCLIDEAN PLANE 3

    way, an unit complex numberz can be written in the form

    z = eiz = cos z+i sin z.

    Hence, the product ofp by the unit complexz is given by

    pz= zp= rei(z+p).

    Therefore,pz is the point in the plane obtained by rotating p by an anglez about theorigin.

    Therefore, we define a biunivoc application : S1 SO(2), representing a rotationof an angle by the complex unit number z = ei. More precisely, we associate the

    the rotation(z) to the complex number z S1 such that (z).p = zp = pz. It iseasy to verify that(z).p= zp= pz. In other words, the product of complex numbersinS1 corresponds to the (composed) product of rotations. Therefore we can work withrotations in the plane using unit complex numbers.

    The linear interpolation of two rotationsz1 =R(1) =ei1 andz2 =R(2) =e

    i2

    can be obtained for the complex number, in an elegant way,as follows

    R(t) =ei[(1t)1+t2], t[0, 1].

    It is easy to verify that the above interpolation equation can still be written in a briefer

    algebraic way:

    R(t) = (z2z

    1

    1 )

    t

    z1, t[0, 1].The representation of a rotation in the plane by a complex number allows obtaining a

    parameterization of the spaceSO(2)defining the exponential applicationexp : RS1,for

    exp(t) =eit = cos t+i sin t.

    Geometrically, this application is defined in the straight tangent line to S1 in the point(0, 1). It applies each real numbertin the extreme point of the arch length |t| going frompoint(0, 1)to point(cos t, sin t)in the circle (see Figure 2). Notice that the exponentialis biunivoc in the interval(, )

    In summary, the representation of rotations by complex numbers is very convenient,

    and it brings several advantages in relation to matrix representation. Amongst them, we

    can mention:

    A 22 matrix (4 components) occupies more storage space of than a complexnumber (2components).

    The number of operations to multiply two complex numbers (4 products) is smallerthan the number of operations to multiply a matrix by a vector (8 products).

  • 7/23/2019 Rotations in Computer Graphics

    4/36

    4 CHAPTER 4: ROTATIONS

    exp(t)

    t

    t

    Figure 2. Exponential application.

    Finally, we do not obtain a good result using matrix representation to compute interpo-lation of rotations: the interpolated matrix

    R(t) = (1 t)

    cos 1 sin 1sin 1 cos 1

    +t

    cos 2 sin 2sin 2 cos 2

    .

    do not represent, in general, even a rotation in the plane.

    Those facts show the representation by complex numbers is superior to the represen-

    tation of rotations by matrices. The study of the space of rotations in R3 is well more

    complex than the two-dimensional case seen above. However, we will see that the re-

    sults of this section admit a good amount of generalization by substituting the complex

    numbers for another set with a similar algebraic structure: the Hamilton quaternions.

    2 Rotations in the Euclidean Space

    Let E = {e1, e2, e3} be the canonical basis of the Euclidean space R3 and F ={f1, f2, f3} an orthonormal basis. The change of basisT: R3 R3, T(ei) = fi de-fines an orthogonal transformation. If the determinant ofTis positive, thenF has thesame orientation ofEand the transformationTis said to be positive. The space of thepositive orthogonal transformations is indicated by SO(3), and it is called orthogonalspecial groupof order3.

    A rigid body does not suffer deformations when moving in the space. Therefore, its

    positioning is completely determined for a reference frame

    {O, f1, f1, f3

    }attached to it

    (local reference frame). The origin O of the reference frame supplies the position of therigid body, and the basis{f1, f1, f3} defines its orientation. Therefore, the orthogonaltransformations determine the orientation of a rigid body in space.

    Our goal is to understand the spaceSO(3). We can state an important first topologicalresult one about this space:

    The spaceSO(3)is compact.

  • 7/23/2019 Rotations in Computer Graphics

    5/36

    SECTION 3: THE SPACE OF ROTATIONS 5

    In fact, it is closed because it is a subset of matrices with determinant 1, and it is limitedonce the columns of a matrix in SO(3)have norm equal to1.

    We will look for a better understanding of the topology and of the geometry of that

    space to obtain good representations and parameterizations. An important result in this

    direction is given by

    Theorem 1. IfRis an element ofSO(3), there is an orthonormal basis ofR3 in whichthe matrix ofRhas the form

    1 0 00 cos sin 0 sin cos

    . (4.2)

    Geometrically, the theorem affirms that a positive orthogonal transformation is givenby one rotation of an angle about an axis (the defined axis for the first vector of thebasis). The above theorem is known in Mechanics as Eulers Theorem1:

    Every orientation is defined by a rotation about an axis.

    Eulers Theorem extends for orthogonal transformations in Rn. A detailed discussion

    can be found in (Lima, 1999). From now on we will refer toSO(3) as space of rota-tions.To understand geometrically the rotations ofR3 and to look for tools for a correctmanipulation are well more difficult than one could imagine at first view. Let us see one

    simple example to convince us.

    Example 1. The set of rotations SO(3), with the usual operation of matrix multiplication,has a group structure. In fact, it is easy to verify that the product of positive orthogonal

    transformations is orthogonal and positive as well. Therefore, ifR1andR2are rotationsabout an r1 and r2 axes, respectively, the product R1R2 is also a rotation. Question:What is the rotation axis of the product?

    3 The space of rotations

    Previously, we saw that the space of rotations in the plane is naturally identified with

    the circleS1, which is naturally embedded in the R2. In reality, this is the topologicalfact that allowed us to obtain a good representation of rotations in the plane. A question

    appears in a natural way:

    Can we represent the spaceSO(3)by a surfaceS R3?We will make a first intuitive attempt for answering the above question. From Eulers

    theorem, a rotation is determined by an axis, which in turn is completely determined by

    1Leonhard Euler (1707-1783), Swiss Mathematician.

  • 7/23/2019 Rotations in Computer Graphics

    6/36

    6 CHAPTER 4: ROTATIONS

    a unit vector in R3

    . Therefore, the set of the axes is naturally identified with the unitsphere in R3:

    S2 ={(x,y ,z)R3; x2 +y2 +z2 = 1}.Besides an axis, we also need a rotation angle, that is one more degree of freedom. We

    therefore see the space of rotations having dimension 3: two degrees of freedom to choosethe axis, and one more degree of freedom to choose the rotation angle about the axis 2 .

    The fact that space SO(3) has dimension 3 indicates some difficulty in its study. In fact,in the case of the plaen we saw that SO(2)has dimension1and it is naturally embeddedin R2. It is topological fact that the tridimensionality ofSO(3), together with his fact itis compact, shows that it cannot be embedded in R3. This means that, topologically, the

    rotations of the R3 space do not belong to R3 and we should look for one representation

    in spaces of larger dimension.

    We begin our search with the matrix representation ofSO(3).

    3.1 Representation by matrices with linkage

    We know that a rotation that takes the canonical basisE={e1, e2, e3} ofR3, in anotherpositive orthonormal basisF ={f1, f2, f3} becomes completely determined by the matrix

    f11 f12 f13f21 f22 f23f31 f32 f33

    ,

    whereT(ei) =

    3j=1fjifj .

    Therefore, in a first inspection, we can parameterize the space of orientations using

    3 3 matrices. In this case, ee would have a representation naturally embedded in theR9 (9degrees of freedom). However, it occurs that the columns of the above matrix arethe coordinates of the vectorsfi that form an orthonormal basis. Therefore,

    |fj|2 =3

    j=1

    f2ij = 1, j = 1, 2, 3. (4.3)

    and

    fi, fj=3

    i=1 fijfik= 0, j=k,j,k= 1, 2, 3. (4.4)

    These six equations reduce the degrees of freedom of choosing the matrix ofT from9 for 3. (In reality, we are defining the space of rotations implicitly in R9.)3 Working

    2In an intuitive way, we have two degrees of freedom by pointing our arm in a direction in space, we still

    have a degree of freedom by rotating the arm longitudinally.3Note we have here another demonstration thatSO(3)has dimension3.

  • 7/23/2019 Rotations in Computer Graphics

    7/36

    SECTION 4: PARAMETERIZATION BY EULERS ANGLES 7

    with such matrix representation has always the problem of guaranteeing that the matricesunder consideration satisfy to the six linkage conditions from equations (4.3) and (4.4).

    That is a difficult problem and computationally costly.

    We will continue with our search by describing a local parameterization of the space

    of rotations which is very used in the Mechanics, and it was discovered by Leonhard

    Euler.

    4 Parameterization by Eulers angles

    Consider the canonical basisE ={e1, e2, e3} ofR3, as shown in Figure 3(a). Thisreference frame defines the Cartesian coordinates(x,y ,z)in space. We will apply three

    consecutive rotations in this reference frame about the coordinate axesz,x andz of thecanonical basis, as described below:

    Rz() :Rotation of an angle about thez-axis (see Figure 3(b));Rx() :Rotation of an angle about thex-axis (see Figure 3(c));Rz() :Another rotation about thez-axis by an angle (see Figure 3(d)).

    e

    Q

    (a)

    e

    Q

    (b)

    e

    Q

    eP

    (c)

    r

    e

    P

    Q

    (d)

    Figure 3. Eulers Angles.

    The product

    Rz()Rx()Rz(), (4.5)

    of the above rotations transforms the canonical basisEinto the orthonormal basisB={b1, b2, b3} shown in Figure 3(d).

  • 7/23/2019 Rotations in Computer Graphics

    8/36

    8 CHAPTER 4: ROTATIONS

    Now let us suppose the orthonormal reference frameB ={b1, b2, b3} is given apriori. Statement: the reference frameBcan be obtained from the canonical basisEby three consecutive rotations . In fact, as we showed in Figure 3(d), let Pbe the planegenerated by the vectors b1 and b2 of the basisB, andr the intersection straight linebetween Pwith the plane z = 0 (r is called nodal straight line in Mechanics). Notice thatthe unit vector e3 b3points towards the direction of the nodal straight line. (In fact, e3andb3 are normal to the planesz = 0and P, respectively. Therefore, the cross producte3 b3should point towards the direction of the intersection straight line between thesetwo planes, which is the nodal straight line.) Let us also indicate by the angle betweenthe vectore1 and the nodal straight line.

    Initially we do a rotationRe3(), of an angleabout the axise3, that takes the vector

    e1 into the vector e1 = e3b3. Soon afterwards, we apply the rotationRe3b3(),

    by an angle about the nodal straight line, which takes the vectore3 into the vectorb3.Finally, we apply the rotationRb3(), by an angleabout the vector b3which takes thevectore1 into the vectorb1. Of course, this sequence of rotations

    Re3()Re3b3()Rb3(), (4.6)

    transforms the canonical basis into the basis B.Notice that thetransformation in (4.5) is equal to the onein (4.6) becauseboth coincide

    in the canonical basisE. However, they apply the rotations in inverse order and withdifferent axes. In the first case, the rotations are always done around the axes of the

    Cartesian (global) system; In the second case, the rotations are applied consecutively inlocal coordinate systems (except forRe3(), of course).We know that a rotationR in space is determined for the positive orthonormal basis

    B={b1, b2, b3}. (The rotation is given by the linear transformation taking the canonicalbasis E={1, 2, 3} into thebasis B). Therefore, we showed above the following result:

    A rotation RSO(3) can be obtained by three consecutive rotations aboutthe coordinate axes.

    This result is owed to Leonhard Euler, and the angles (,,) are called Eulersangles. They constitute a parameterization of the spaceSO(3). This parameterization isused broadly in the study of rigid bodies dynamics in R3.

    4.1 Yaw, Pitch and Roll

    In the previous section, we saw two different choices of parameterizations by Eulers

    angles, with different rotation axes and order about them. The parameterization ofSO(3)using Eulers angles is broadly used in the Computer Graphics aiming at specifying

    rotations. It is common to use names brought from aviation: yaw (deflection angle),

  • 7/23/2019 Rotations in Computer Graphics

    9/36

    SECTION 4: PARAMETERIZATION BY EULERS ANGLES 9

    pitch (steepness angle), roll (longitudinal rotation angle), as shown in Figure 4(a). In thisconvention, the roll, yaw and pitch axes are the z, x, and y axes, respectively (Figure 4(b)).

    4.2 Eulers angles and matrices

    We are going to describe a rotation matrix parameterized by Eulers angles. Indicating

    the rotation angles about the 1, 2 and 3axes for,and , respectively, gives us therotation matrices at each axis:

    Rx() = 1 0 00 cos

    sin

    0 sin cos

    Ry() =

    cos 0 sin 0 1 0

    sin 0 cos

    Rz() =

    cos sin 0sin cos 0

    0 0 1

    Making the product of these three matrices, in the order Rz()Ry()Rx() (which isthe order used to obtain equation (4.6)), we obtain the parameterization R(,,)of the

    rotation matrix,cos cos cos sin sin cos sin cos cos sin + sin sin cos sin cos cos + sin sin sin cos sin + cos sin sin

    sin cos sin cos cos

    . (4.7)

    which is calledEulers matrix. Notice thatRdefines an applicationR : R3 R9.

    Pitch

    Roll

    Yaw

    (a)

    y

    z Roll

    Pitch

    Yaw x

    (b)

    Figure 4. Eulers Angles.

  • 7/23/2019 Rotations in Computer Graphics

    10/36

    10 CHAPTER 4: ROTATIONS

    4.3 Singularities and Eulers anglesEulers angles do not constitute a global parameterization of the space of rotations. The

    reason being the space SO(3) is compact, and therefore it cannot be parameterized byan open set ofR3 (in the same way a sphere S2 R3 does not admit a global parame-terization for an open subset in the plane). In this way, any attempt of extending Eulers

    angles to cover the whole space of rotations leads to the creation of singularities in the

    parameterization. These singularities are regions in the domain of the parameterization

    in which we do not have the three degrees of freedom in the rotation matrix (see the dis-

    cussion of singularity in the parameterization of the sphere in the chapter on coordinate

    systems).

    We can describe singularities of the parameterization for Eulers angles by taking

    =/2in the parameterizationR(,,)of equation (4.7). That is, doing a rotationof90 about they-axis (pitch), we obtain the parameterization

    R(,

    2, ) =

    0 cos sin cos sin cos cos + sin sin 00 cos cos + sin sin cos sin cos sin 0

    1 0 0 0

    =

    0 sin( ) cos( ) 00 cos( ) sin( ) 0

    1 0 0 0

    .

    We see that, despite having two degrees of freedom in the parameter space, we have

    just one degree of freedom in the parametrization. This is because the parametrized

    matrix only depends on the difference of the angles. (This phenomenon is similar to the

    singularity in the parameterization of the sphere that we saw in the chapter of coordinate

    system.)

    It is easy to understand intuitively the singularities of the parameterization ofSO(3)using Eulers angles. In fact, the angles perform three consecutive and independent

    rotations in each one of the coordinate axes: first we rotate aboutz , then about y , andlater aboutx. The singularities happen as two axes of rotation point towards the samedirection. This is because the rotations about those two axes are dependent and therefore

    we loose a degree of freedom.

    The gimbal lock phenomenon

    The problem of singularities of Eulers angles manifests in practice. The phenomenon is

    known in Aeronautical Engineering and Mechanical Engineering as gimbal lock 4.

    4Gimbal is the given name to the mechanical assembly of equipments requiring a space orientation and,

    for that end, using Eulers angles: for example, gyroscope, optic equipments

  • 7/23/2019 Rotations in Computer Graphics

    11/36

    SECTION 5: INTERPOLATION OF ROTATIONS 11

    Roll

    Pitch

    Figure 5. Gimbal lock phenomenon.

    Notice the example in the model shown in Figure 5. As the yaw-axis is fixed, after

    a pitch-axis rotation (leaving the airplane heading in the vertical direction), the roll and

    yaw axes coincide. In this position we loose a degree of freedom in the rotation about

    those two axes.

    Of course, by restricting the variation of the Eulers angles, we eliminate the singular-

    ities problem. For this reason, the pilot of an airplane does not have the same problems

    of an animator (fortunately!).

    5 Interpolation of rotations

    We already had the opportunity to discuss in several occasions the importance of inter-

    polation methods in Computer Graphics. They are responsible for the reconstruction of

    the objects starting from a set of samples.

    The general problem of interpolating rotations consists in interpolating points in the

    spaceSO(3), and it can be stated in the following way:

    Givenn rotationsR0, R1, . . . , Rn, obtain a curveR : [0, 1] SO(3), ofclass Ck, k 0, and a partition 0 = t0 < t1

  • 7/23/2019 Rotations in Computer Graphics

    12/36

    12 CHAPTER 4: ROTATIONS

    Figure 6. Moving a boomerang by interpolating Eulers angles.

    between two objectsR0andR1is alinear interpolation, defined asR(t) = (1 t)R0+tR1,t[0, 1].

    In the case R0 andR1 are matrices, then linear interpolation makes sense, becausethe space of matrices is a vector space. However, ifR0 andR1are rotation matrices, thematrixR(t) = (1 t)R0+ tR1,t[0, 1], in general does not represent a rotation. Thishappens because the space of rotationsSO(3) is not a linear subspace of matrix space.(The problem here is similar to a linear interpolation between two points on a sphere: the

    resulting segment is not contained in the sphere.)

    5.1 Interpolating Eulers angles

    When we have a parameterization : U Rm

    Sof a space S, the interpolationproblem is reduced to interpolate in the parameters space U. In fact, to interpolate npointsp1, . . . , pnS, we take the corresponding points 1(p1), . . . , 1(pn), in theparameters space U Rn, and we obtain an interpolation curve c : [0, 1] : Rm amongthose points. The desired interpolation curve is given by the composite c : [0, 1]S.Therefore, the interpolation problem is reduced to one in Rm, which is broadly covered

    in the literature.

    In particular, the above principle is applied to interpolate rotations using the pa-

    rameterization by Eulers angles as shown in Figure 6. In this case, if we have two

    rotationsR0 = R(0, 0, 0) andR1 = R(1, 1, 1), we obtain a curvec in the pa-rameters space,c(t) = ((t), (t), (t)), such thatc(0) = ((0), (0), (0)) =R0and

    c(1) = ((1), (1), (1)) =R1. The interpolating path in SO(3)is given by the com-positeR(t) =R((t)), R((t)), R((t)), whereR= Ris the Euler matrix given inthe equation (4.7). (we can of course use this method to interpolatenrotations.)

    The advantage of this method is that the interpolation itslef is done in the R3 space.

    In this way, we can interpolate an arbitrary number of rotations using the various point

    interpolation methods of interpolation described in the literature (e.g. Splines, Bezier,

    Hermite). This method is, of course, applicable to any other parameterization of the space

  • 7/23/2019 Rotations in Computer Graphics

    13/36

    SECTION 6: PAUSE FOR COMMERCIALS 13

    of rotations.The interpolation of Eulers angles is the method used in the majority of keyframe

    animation systems to specify the orientation of the objects and of the virtual camera. The

    disadvantages of this method are all those inherent to the parameterization method with

    Eulers angles that we will discuss next.

    6 Pause for commercials

    The parameterization of the space of rotations using Eulers angles is broadly used inthe area of Animation. A sequence of rotations with Eulers angles is represented by a

    three-dimensional curve where each component represents a rotation angle in each axis.

    Therefore, the animators work by manipulating curves in the R3 space to modify path,

    speed, acceleration etc. In general, the editing is made over the projection of these curves

    in the coordinate planes, an interface in which animators are already quite familiar with.

    Another advantage of matrices, and in particular of Euler matrices, is that other pro-

    jective transformations are also represented by matrices, especially translation.

    However, besides the problem of singularities (gimbal lock), discussed above, the

    parameterization for Eulers angles has several other inconvenients.

    Given a rotation matrix, we can have ambiguities in the solution of the inverse problem.

    What are the axis and rotation angle?The representation for Eulers angles has no unicity because it depends on the order

    of the axes (anisotropy);

    The parameterization defines a local coordinate system in the space of rotations; In

    other words, we cannot describe all rotations using just an Euler coordinate system. Of

    course, we can use several parameterizations to cover the SO(3) space; However, it isnot simple to perform a change of coordinates between two systems of Eulers angles.

    Finally, specifying rotations using Eulers angles is difficult and not intuitive. Let us

    see a practical example: hold a football ball, mark a point on it with a pen and rotate it to

    place the marked point in the vertical position (north pole of the ball). Easy, right? Now

    try to solve the same problem with three successive rotations about the axes according

    to Eulers parameterization. In the first solution, in an intuitive and natural way, we usedEulers Theorem, by doing a single rotation about an axis.

    The above fact shows that we should look for a representation ofSO(3)where eachrotation is represented by its axis, together with the rotation angle. To have this intuitive

    representation mathematically efficient, we need to introduce a mathematical structure

    in space constituted by the elements axis + rotation angle . This will be our goal in

    the remaining of this chapter.

  • 7/23/2019 Rotations in Computer Graphics

    14/36

    14 CHAPTER 4: ROTATIONS

    7 Quaternions

    Quaternions introduce an algebraic structure in the Euclidean space R4 similar to the

    structure of the complex numbers in the R2 plane. This structure allows to obtain a

    representation of the space of rotations based on the axis+angle model to define a

    rotation.

    We denote as{1, i,j, k} the canonical basis of the space R4: 1 = (1, 0, 0, 0), i =(0, 1, 0, 0), j = (0, 0, 1, 0) and k = (0, 0, 0, 1). A pointp = (w,x,y ,z) R4 is thenwritten in the form p = w +xi +yj +zk. Amongst the four elements1, i,jand k ofthe basis, we define aproductaccording to the table below:

    1 i j k1 1 i j k

    i i -1 k jj j -k -1 i

    k k j -i -1

    Table 1: Multiplication of the quaternions in the basis.

    Notice that the product is not commutative. We extended the above product to obtain

    the productpq between two arbitrary points ofR4 requiring bilinearity. In other words,

    ifp1, p2, q1, q2

    R4, we have

    (ap1+ p2)(bq1+ q2) =abp1q1+ap1q2+bp2q1+ p2q2.

    The space R4, with the above multiplicative structure, is called quaternions spaceor simply quaternions. Quaternions were discovered by William Hamilton5 with thegoal of obtaining in the space the same relation between rotations and complex numbers

    that exists in the plane. The operation of quaternion product is distributive, associative

    (tedious check), and, highlighting once again, not commutative.

    The subspaceR1={(x, 0, 0, 0); xR} is identified with the set of thereal numbers,and it is called space of scalars; the subspaceR i+Rj+Rk={(0, x , y , z); x,y ,z R}is naturally identified with the Euclidean space R3 and it is called space of vectors or

    space of pure quaternions. Given a quaternion u R4, u = w+ xi+yj+zk, thenumberw is calledreal partofu and it is indicated by(u); the vectorxi +yj +zk,is called ofvector part ofu. Ifv = (x,y ,z) R3 is a vector, we indicate by v theassociated pure quaternion: v = xi+ yj+ zk. In this way, every quaternion can bewritten in the formp = w+v,w R,v R3.

    5Sir William Rowan Hamilton (1805-1865), Irish mathematician.

  • 7/23/2019 Rotations in Computer Graphics

    15/36

    SECTION 7: QUATERNIONS 15

    Theconjugatedof a quaternion u= w + v is defined by u

    =w v. In other words,ifu= w + xi +yj+ zk, then u =w xiyjzk. The conjugation operation satisfiesthe properties(u) =u and (uv) =uv. Of course, the real part of a quaternionuis equal to (u) = (u + u)/2.

    Thenormof a quaternion p = w +xi +yj +zkis equal to the norm of the vector(w,x,y ,z)in the Euclidiano inner product ofR4:

    |p|=

    p, p=

    w2 +x2 +y2 +z2.

    Of course ifp = w+vthen |p|2 =w2 + |v|2.Also, |p|=|p|. The norm behaves well in relation to the quaternion product (verify):

    |p1 p2|=|p1||p2|. (4.8)If|p|= 1, we say p is a unit quaternion. Of course, the set of unit quaternions form theunit sphereS3 R4,

    S3 ={(w,x,y ,z)R4; w2 +x2 +y2 +z2 = 1}.Besides, for (4.8), the product of two unit quaternions is a unit quaternion. Therefore,

    S3 is a group, as seem as the set of unit quaternions. (Notice here the analogy with thecircleS1 R2 that is a group formed by the complex numbers of norm 1.)

    Themultiplicative inverseof a quaternion u, is a quaternion u1 such thatuu1 =u1u = 1. An immediate calculation shows that every nonull quaternionu has one

    multiplicative inverse given by

    u1 = u

    |u|2 ,

    Notice if|u|= 1, thenu1 =u.Ifq1= a1+v1 and q2 = a2+v2, a direct calculation shows that the product ofq1

    andq2 is given by

    q1q2= a1a2 v1,v2 +a1v2+a2v1+v1v2.We are using the notation v1v2 to indicate v1 v2. Therefore, ifq1 and q2 are purequaternions, that is,a1= a2= 0, then

    q1q2=v1,v2 +v1v2.Therefore, the quaternion product synthesizes two types of vector products in R3: the

    scalar and cross products (in a way this let us foresee the great potential of this operation).

    Notice ifv is a pure quaternion,v v= 0, and by taking q1= q2= v in the previousequation, we obtain

    v2 =v, v=||v||2.

  • 7/23/2019 Rotations in Computer Graphics

    16/36

    16 CHAPTER 4: ROTATIONS

    In particular, ifv is a unit pure quaternion, we have v2

    =1.Every quaternionq= a+v can be written in the form a +bu, where|u| = 1 is a

    unit quaternion. In fact, we can only take

    u= v

    |v| , e b=|v|.

    Observe that the representation of a quaternion in the formq = a+bu, as |u|= 1, thatis, u is a pure unit quaternion, we have u2 =1. Yet, in this representation, ifq is unit,we have

    1 =|q|2 =a2 +b2|u|2 =a2 +b2.Therefore, there exists R such that a = cos and b = sin , and we can writeq= cos + sin u.

    Notice the similarity of what we have obtained above with the complex numbers. A

    complex number has the form x + iywith i2 =1; Besides, every unit complex number,i.e. of norm1, can be written in the form cos +i sin . The difference is that, unlikethe complex numberi, the unit quaternion u, in the representationp= a+bu, dependson the quaternionp.

    The results here show that quaternions have algebraic properties similar to the ones

    in complex numbers, with exception for commutativity. Our final test is to try to extend

    the result involving complex numbers and rotations of the plane to quaternions. This is

    the subject of the next section.

    7.1 Representation of rotations by quaternionsGiven a unit quaternion q, we should define the transformation Rq : R4 R4 placingRq(p) = pq. We have|Rq(p)| =|p||q| =|p|, therefore the transformation Rq isorthogonal. That is, multiplications for unit quaternions geometrically correspond to

    rotations in R4 space. Now, a natural question comes into play:

    How to obtain a representation ofSO(3)by quaternions?

    A first idea would be to associate, to each quaternion q R3, the transformationRq.Unfortunately, in general,Rq /SO(3), that is, the space of pure quaternions, naturallyidentified with R3, is not invariant for Rq. The representation ofSO(3)by quaternionsis a little subtler as we will see.

    Observe that the representation of a unit quaternion q in the form q= cos +sin u,with|u| = 1, shows this quaternion defines an angle and an axis uof the space. It isnatural to expect this quaternion to represent a rotation about theu-axis . We will show

    this in fact happens and the angle of that rotation is2.Given a unit quaternion q, we define the transformationq : R

    3 R3, placingq(v) =qvq

    1 =qvq, v R3. (4.9)

  • 7/23/2019 Rotations in Computer Graphics

    17/36

    SECTION 7: QUATERNIONS 17

    We will demonstrate several properties soon afterwards of that transformation.the transformationqis well defined. This meansq(v)R3. For that, it is enough

    to show (q(v)) = 0:

    (qvq1) =(qvq);= [qvq + (qvq)]/2;

    = [qvq + qvq]/2;

    =q[(v +v)/2]q;

    =q(v)q =(v)qq =(v) = 0.

    The transformationqis linear. In fact,

    q(au +v) =q(au +v)q

    =qauq +qvq

    =a(quq) + (qvq)

    =aq(u) +q(v).

    The transformationqis orthogonal. In fact,

    |q(v)|=|qvq|=|q||v||q|=|v|.

    The transformation q is a rotation ofR3. In fact, as we saw above, it is enough toshowq is positive. In this case, notice forq = 1q = I, whereI: R

    3 R3 is theidentity transformation. As the space of unit quaternions is connected (because it is the

    unit sphere in R4), we conclude by a continuity argument that q is positive for everyquaternionq. The axis of rotation ofqis the quaternion u. In fact, it is enough showthatq(u) =u:

    q(u) =quq

    = (cos +u sin )u (cos u sin )= (cos )2u (sin )2u3= (cos )2u

    (sin )2(

    u)

    =u.

    The angle of rotation ofqis2. We will make a geometric demonstration of thisfact, by solving the following problem:

    Given a rotationR of an angle about an axis r, how can we obtain thequaternion qof the representationqinR?

  • 7/23/2019 Rotations in Computer Graphics

    18/36

    18 CHAPTER 4: ROTATIONS

    O

    P P

    H V

    Figure 7. Rotation of an angle about the axis defined by vectorn

    To answer the above question, consider Figure 7 showing the rotationR of pointP byan angleabout theOH-axis. The image of point Pis the pointP =R(P).

    Let us take the positive reference frame{u, v, n}, whereu =HP,v =HV andnis the unit vector in the direction of the rotation axis. We also define the vectors

    h=OH , p=

    OP , p =

    OP, and u =

    HP.

    withuh,hv and |v|=|u|. Havingh as the orthogonal projection ofp in thedirectionn, we haveh =p, nn. It is also easy to verify that

    p =h + u

    u= p h= p p, nnu = cos u + sin v,

    and besides,

    v= n u= n (p h) =n (p p, n) =n p.We then have

    R(P) =OP =h + u

    =n, pn + cos u + sin v=n, pn + cos (p p, nn) + sin n p= cos p + (1 cos )n, pn + sin n p.

    (4.10)

    We will now calculate R(P) using the rotationq in (4.9). In this case point P isrepresented by the pure quaternion, P = p, and q is the unit quaternion q = cos +

  • 7/23/2019 Rotations in Computer Graphics

    19/36

    SECTION 7: QUATERNIONS 19

    n sin . To simplify the calculations let us takec = cos and t = n sin , thereforeq= c+ t. We then have

    R(P) =q(p) =qpq

    = (c+ t)(p)(c t)= (c+ t)(p, t p t +cp)=cp, t t, p t ct,p+

    + t (p t) +c(t p) +c(p hatt +cp) + p,hatthatt)=hatt,phatt hatt,hattp + 2c(hatt p) +c2p + p,hatthatt)= (c2

    hatt,hatt

    )p + 2

    p,hatt

    hatt + 2c(hatt

    p).

    (4.11)Substituting the values ofc = cos and t = n sin , in the expression ofq(p)

    obtained in equation (??), we have

    R(P) = (cos2 sin2 )p + 2 sin2 p,nn + 2 sin cos (n p)= cos 2p + (1 cos2)n,pn + sin 2(n p)).

    Comparing this equation with (4.10) we see thatq(p)is a rotation of an angle2aboutthe axis defined by the unit vectorn.

    The results demonstrated above can be summarized in

    Theorem 2 (Representation of rotations for quaternions). A rotation of an angle 2

    about an axis defined by a unit vector n is represented by q(v) = qvq1, whereq= cos +n sin .

    Therefore, we have a transformation : S3 SO(3),(q) =q, representing therotations in space for points of the unit sphere in R4. Following up, from the definition

    ofq, we haveq = q. Geometrically, this fact is obvious because a rotation of anangle about then-axis is the same to a rotation of an angle2 about the n-axis.Therefore, the transformationq is not injective. However, it can be shown, without alot of difficulty, that

    q1 =q2 q1=q2.We left that demonstration for the exercises at the end of this chapter.

    The above result shows that only the antipode points of the sphere define the samerotation. Therefore, the space SO(3) is identified naturally with the unit sphere S3 inR4 with the antipode points identified. We know this is the real projective space of

    dimension3, RP3. We will not use, however, this association between SO(3)and RP3.The important aspect of the above result is that space SO(3) of the rotations can berepresented by unit quaternions. Care should only be taken with antipode points of the

    sphere representing the same rotation.

  • 7/23/2019 Rotations in Computer Graphics

    20/36

    20 CHAPTER 4: ROTATIONS

    An important fact in relation to the representation of rotations in SO(3) by quaternions,is the product operation is preserved, that is

    u1u2 =u1u2.

    The check is immediate: for every vector v R3 we have

    u1u2(v) =u1u2v(u1u2)1 =u1u2vu

    12 u

    11 =u1u2v u

    11 =u1u2(v).

    This fact shows we can substitute the product of two rotation matrices by the product of

    the quaternions representing them. In particular, notice this result answers a question we

    had in the beginning of the chapter:

    If rotationsR1 andR2 have axes defined by the unit vectors u1 andu2,respectively, then the axis of the rotation productR1R2 is the product ofquaternions u1u2.

    7.2 Exponential and logarithm

    Consider a vector v R3, v= 0. and letv= v/|v| be the pure unit quaternion obtainedfromv by normalization. Using the notation =|v|, we havev = v. Substituting theexpressionv = vin the Taylor series of the exponential function we obtain,

    ev =ev =n=0

    (v)n

    n! .

    An immediate calculation, taking into account v2 =1, gives us

    ev =ev = cos +v sin = cos |v| +v sin |v|.

    We can define the exponentialexp : R3 S3 having

    exp(v) =

    cos |v| + sin |v|v, sev= 0;1= (1, 0, 0, 0) sev = 0,

    wherev=|v|/|v|. We will also use the notationexp(v) =ev. Notice that ifvis a unitquaternion, thenv = cos + sin u, with |u|= 1. As |u|= , we have

    eu = cos + sin u,

    which is a similar expression to ei = cos +i sin for complex numbers.

  • 7/23/2019 Rotations in Computer Graphics

    21/36

    SECTION 7: QUATERNIONS 21

    Now we can define the logarithm functionlog : S3

    R3

    , as being the inverse of theexponential. GivenqS3,q = cos + sin u, |u|= 1, we have

    log(q) =uR3.It is immediate verifyingelog(q) =q.

    It is sometimes useful to have the definition of the exponential and of the logarthm

    explicitly showing the coordinates; Ifu = w+xi +yj +zkS3, we can write

    log(w,x,y ,z) = arccos(w) (x,y ,z)

    x2 +y2 +z2=

    arccos(w)x2 +y2 +z2

    (x,y ,z).

    Similarly, ifv = (x,y ,z)R3, we have

    exp(x,y ,z) =

    cos(

    x2 +y2 +z2) +

    sin(

    x2+y2+z2)x2+y2+z2

    (x,y ,z), se(x,y ,z)= 0;(1, 0, 0, 0) if(x,y ,z) = 0.

    Now we can define arbitrary potencies of unit quaternions extending in a natural way

    the result for complex numbers: ifq is a unit quaternion andtR, we haveqt =et logq =etu = cos(t) + sin(t)u. (4.12)

    Observe that the expression c(t) = qt (with t varying in the interval [0, 1]) defines acurvec : [0, 1]

    S3 that ties the pointc(0) =1 = (1, 0, 0, 0)(north pole of the sphere

    S3) to the point c(1) = q. We will give a geometric interpretation of this curve, and atthe same time of the exponential function. For that we needed some definitions.

    Amaximum circle of the sphere S3 is a circle of radius 1, in other words, a circlecontained inS3 that has maximum radius. A maximum circle is obtained by the inter-section ofS3 with a subspace of dimension 2 in R4. Ageodesic ofS3 is a maximumcircle parameterized for a curvec : [0, 1] S3 such that the speed|c(t)| is constant.This implicates that the image of an uniform partition of the parameter space [0, 1] resultsin an uniform partition of the maximum circle. (The geodesics are the straight line

    of the sphereS3 when walking between two points on the sphere; The smallest path isalways along a geodesic).

    Let us return to equation (4.12), from which, geometrically, the curve c(t) = qt

    represents a family of rotations about the same u-axis with given angles by2t. InS3,these rotations represent an arch of maximum circleconnecting the quaternion c(0) =1 tothe quaternion c(1) =q. We left as an exercise at the end of thechapter the demonstrationthat

    c(t) = d

    dtqt =qt log q.

    Then it is easy to verify that the curvec(t)holds the following properties:

  • 7/23/2019 Rotations in Computer Graphics

    22/36

    22 CHAPTER 4: ROTATIONS

    Figure 8. Exponential application.

    1. c(0) =u;

    2.|c(t)|=||;3. c(t) =kc(t), wherek

  • 7/23/2019 Rotations in Computer Graphics

    23/36

    SECTION 7: QUATERNIONS 23

    promised previously: the axis is modeled by a vector, and the angle is its length (less offactor2).

    As we are parameterizing SO(3) byR3, of course, the exponential holds singularities.Using the geometric interpretation of the exponential it is easy to conclude that the spheres

    of radiusk, k = 1, 2, . . . are singularities regions of this parameterization. They arethe regions ofR3 mapped in the north pole or in the south pole of the sphere S3. Thesesingularities can be avoided in practice: whenv approaches the sphere of radius, wehave a rotation of an angle = 2|v| close to2, we then change for a rotation of an angle2 about the v-axis that is equivalent and far away from the singularity.

    Observing the definition of exponential parameterization attentively, we notice that we

    can have a problem of numerical instability in the calculation of the unit vector u= v/|v|,whenv0. This problem can be avoided. In fact, we have

    ev = cos |v| + sin |v|u= cos |v| + sin |v| v|v|= cos |v| +sin |v||v| v.

    Now we only need to observe that sin |v||v| 1 when|v| 0. In reality, for implemen-

    tation purpose, we can substitute this function by an approximation given by its Taylor

    series:sin t

    t = 1 +

    t2

    3!+

    t4

    5!+

    +

    t2(n1)

    (2n 1)!+

    7.3 Interpolating quaternions

    In this section we will cover the topic of interpolating rotations using the representation by

    quaternions. We will just study the case for two rotations. Let us consider two rotations

    uand vof angles uand vabout unit axes u and v, respectively. These two rotationsare represented by unit quaternions as indicated below:

    u p= euu = cos u+ sin uuv q= evv = cos v+ sin vv

    We then have

    u(x) =pxp e v(x) =qxq

    .

    Quaternions p and q define an arch of maximum circle in the sphere S3 (see Figure 9(a)).Due to the representation of rotations by unit quaternions, an interpolation between

    the rotations u and v is simply a curve g : [0, 1] S3 in the sphere S3 such thatg(0) =p andg(1) =q. That is, the interpolation of rotations is reduced to a problem ofinterpolating points inS3.

  • 7/23/2019 Rotations in Computer Graphics

    24/36

    24 CHAPTER 4: ROTATIONS

    Linear InterpolationAs quaternions hold the usual linear structure ofR4, we can do a linear interpolation

    betweenp and q. More precisely, we define the quaternion

    a(t) = (1 t)p +tq,and the interpolated rotation is given bya(t)where

    a(t)(x) =a(t)xa(t).

    The problem of this method is that a(t)are not unit quaternions. In fact, geometricallythey form a rope of the maximum circle of the unit sphere S3 R4 containing thequaternionsp and q (see Figure 9(b)).

    We can bypass this problem by doing aspherical radial interpolation, consisting oftaking the radial projection ofa(t)on the unit sphere, as shown in Figure 9(b). That is,

    a(t) = a(t)

    |a(t)| = (1 t)p +tq|(1 t)p +tq| .

    This method works; However, we do not have an uniform sampling in the angles even

    when the sampling is uniform in time. (That is, the projection is a maximum circle but it

    is not a geodesic.) This fact can be observed in Figure 9(c). In other words, the angular

    speed is variable (it accelerates and decelerates.).

    Geodesic interpolation

    Our goal now is to correct the problem of spherical radial interpolation and to obtain

    a interpolation between two quaternions in which the interpolating curve has constant

    angular speed, that is, an uniform sampling in time generates an uniform sampling in the

    angles. As we know already, it is enough to do the interpolation along a geodesic of the

    sphereS3 tieing quaternionsp to q. This method is calledgeodesic interpolation.Previously, we saw that curve c(t) = bt is a geodesic tying the north pole 1 of the

    sphere to quaternion b. This provides a geodesic interpolation between rotations 1andb.

    p q

    (a)

    p q

    (b)

    p q

    (c)

    Figure 9. Quaternion interpolation.

  • 7/23/2019 Rotations in Computer Graphics

    25/36

    SECTION 7: QUATERNIONS 25

    How to obtain a geodesic tieingp to q? A simple calculation shows the curve

    g(t) = (qp)tp, t[0, 1], (4.13)

    satisfiesg(0) =p andg(1) =q. It remains to showg(t)is a geodesic. For this, observethatg(t) =Rp(c(t))wherec(t) = (qp)

    t andRpis the transformation ofS3 defined byRp(v) =vp. Now we knowc(t)is a geodesic; On the other hand, the transformationRp is orthogonal, therefore preserving geodesics for being an isometry of the sphere.(In more geometric terms: a geodesic is a maximum circle and sphere rotations preserve

    maximum circles.)

    In conclusion, equation (4.13) defines a geodesic interpolation between quaternions

    p and q. This interpolation method is calledspherical linear interpolation or, briefly,slerp.Next, we will obtain an expression of geodesic interpolation which is very common in

    the literature; It expresses the interpolation parameter in terms of angles in the maximum

    circle tieing p to q. Let be the angle between quaternions p and q, thatis, cos =p, q(Figure 10(a)).

    (a) (b)

    Figure 10. Spherical linear Interpolation.

    As we will work with angles of the maximum circle, our problem is reduced to a

    planar one. (That is, we work in the plane of the maximum circle, defined by p,q and

    the origin). Observing Figure 10(b), we have:

    p= (cos(0), sin(0)),

    q= (cos(0+), sin(0+)).

    Therefore, in terms of angles, the interpolation between p and q is given by

    g(t) = (cos(0+t), sin(0+t)).

  • 7/23/2019 Rotations in Computer Graphics

    26/36

    26 CHAPTER 4: ROTATIONS

    Now we should write this expression as function of quaternionsp and q. That is achievedwith a simple calculation, using trigonometry (we will indicate a vector (x, y) in the plane

    by a column matrix

    xy

    , due to space contraints):

    g(t) =

    cos(0+t)sin(0+t)

    =

    cos(0) cos(t) sin(0)sin(t)sin(0) cos(t) + cos(0)sin(t)

    = cos(0)[sin() cos(t)cos()sin(t)]+[cos(0) cos()sin(0) sin()] sin(t)

    sin()sin(0)[sin() cos(t)cos()sin(t)]+[sin(0) cos(t)+cos(0) sin()] sin(t)

    sin()

    =

    cos(0) sin((1t))+cos(0+) sin(t)

    sin()sin(0) sin((1t))+sin(0+) sin(t)

    sin()

    =

    cos(0)sin(0)

    sin((1 t))

    sin() +

    cos(0+)sin(0+)

    sin t

    sin()

    =psin((1 t))

    sin + q

    sin(t)

    sin .

    In short, we have

    slerp(p, q, t) =p

    sin((1

    t))

    sin + q

    sin(t)

    sin . (4.14)

    7.4 Some afterthoughts

    The representation of rotations by quaternions brings many advantages. Among them

    we can enumerate:

    1. Smaller storage space (a quaternion has four components and a matrix holds nine,

    or 16 in homogeneous coordinates).

    2. We have a global parameterization, thus facilitating the interpolation of rotations

    (we interpolated in the unit sphereS3 R4).3. The interpolation of rotations is reduced to a problem of interpolating points in the

    unit sphere (unit quaternions).

    4. The exponential parameterization translates the natural way we think about rota-

    tion: axis+angle.

    5. The representation is intrinsic (i.e. it does not depend on coordinates)

  • 7/23/2019 Rotations in Computer Graphics

    27/36

    SECTION 8: CONVERTING AMONG REPRESENTATIONS 27

    6. Quaternion product can be implemented in a more efficient way than matrix prod-uct.

    On this last item, notice that multiplication of two quaternions has 16 products, while

    the multiplication of matrices has 27 products. In reality, even more surprisingly, the

    multiplication of two quaternions can be obtained with only 8 products (see exercises).

    A problem with using quaternions is that several existent geometry libraries are in

    general designed to work with matrices, and in particular with Eulers angles. Therefore,

    it is convenient to have the expressions to convert among the several representations (i.e.

    matrix, Eulers angles, quaternions, exponential parameterizatione). We will cover this

    subject in the next section.

    8 Converting among representations

    In this section we will study two types of conversions among representations: from

    quaternions to matrix, and from Eulers angles to quaternions. We already saw previously

    the conversion from Eulers angles to matrices.

    8.1 Quaternions and matrices

    In this section we will find the rotation matrix represented by

    q(v) =qvq1,

    whereq is a unit quaternion.

    Before, let us draw a parallel with complex numbers. There exists a relation between

    the product of complex numbers and linear transformations. Let us associate, to each

    complex numberz = a+bi, a linear transformationLz : R2 R2, defined by

    Lz(x, y) =z(x+iy) = (a+bi)(x+iy) = (ax by,bx+ay).

    The transformation matrix ofLz is given by

    a bb a ,

    which can be verified with a direct calculation. We will extend this result for quaternions.

    Initially, we observed that when a quaternion q = w1+ xi+ yj+ zk representsa vector ofR3 in homogeneous coordinates, the infinite coordinate is given by variable

    w. In Chapter 2 (Geometry) we took the coordinate of the point in the infinite as beingthe last coordinate. In this case, the vector corresponding to quaternion q is given by

    (x,y ,z ,w).

  • 7/23/2019 Rotations in Computer Graphics

    28/36

    28 CHAPTER 4: ROTATIONS

    Let q1 = (x1, y1, z1, w1) and q2 = (x2, y2, z2, w2) be two quaternions. From thebilinearity of quaternion product, we know the product q1q2 is linear in q1 and q2.

    Therefore we have two linear transformations: Lq1: R4 R4, andRq1: R4 R4,

    defined respectively, for the product to the left and right of quaternion q1:

    Lq1(q) =q1q, e Rq1(q) =qq1.

    A direct calculation shows the matrices of these linear transformations are given by

    Lq1(q) =

    w1 z1 y1 x1z1 w1 x1 y1

    y1 x1 w1 z1

    x1

    y1

    z1 w1

    xyzw

    (4.15)

    and

    Rq1(q) =

    w1 z1 y1 x1z1 w1 x1 y1y1 x1 w1 z1

    x1 y1 z1 w1

    xyzw

    . (4.16)

    We can use any one of these two transformations to represent the product of two

    quaternions using linear transformations. We observed that this association is analog to

    the association between complex numbers and matrices we presented in the beginning

    of this section. Here we have two possibilities because the product of two quaternions it

    is not commutative. (Notice that ifq1 is unitary, then transformationsLq1 andRq1 are

    orthogonal.)It is important to highlight that this relation between quaternions and linear transfor-

    mations preserves the product and sum operations in each one of these spaces. More pre-

    cisely, quaternion q1(q2+q3) corresponds to matrixLq1(Lq2+Lq3), or Rq1(Rq2+Rq3).As quaternions product is associative, we have

    (q1p)q2 = q1(pq2).

    Using transformationsL andRthis expression can be written in the form

    Rq2Lq1p= Lq1Rq2p.

    This relation is very important from the computational point of view. In fact, in a quater-

    nion productq1q2. . . qi1qiqi+1. . . qN, (4.17)

    if only quaternion qi varies, we can combine the products q1q2. . . qi1 in a matrixLq1q2...qi1 , and the product qi+1. . . qN in a matrix Rqi+1...qN, and then write theproduct of (4.17) in the form

    Lq1q2...qi1Rqi+1...qNqi.

  • 7/23/2019 Rotations in Computer Graphics

    29/36

    SECTION 8: CONVERTING AMONG REPRESENTATIONS 29

    Wewillnowfindthematrixin SO(3) corresponding to the rotation defined by q(v) =qvq1.As q is unitary, we have q1 =q, and therefore it is proceeded that

    q(v) =L(q)R(q)(v). (4.18)

    Ifq = (x,y ,z ,w), thenq = (x, y, z, w). Using the matrix ofLq1 in (4.15) withq1= q and the matrixRq1 in (4.16) with q1= q

    , and substituting in (4.18), we obtain

    L(q)R(q) =

    w z y xz w x y

    y x w z

    x

    y

    z w

    w z y xz w x y

    y x w zx y z w

    .

    Doing the product, we obtain the matrix

    w2 +x2 y2 z2 2xy 2wz 2xz+ 2wy 02xy+ 2wz w2 x2 +y2 z2 2yz 2wx 02xz 2wy 2yz + 2wx w2 x2 y2 +z2 0

    0 0 0 |q|2

    . (4.19)

    (See exercise 3 for another form of writing this matrix.) As the quaternionq is unitary,

    we have

    |q|2 =w2 +x2 +y2 +z2 = 1.

    In Cartesian coordinates the above matrix can be written in the formw2 +x2 y2 z2 2xy+ 2wz 2xz 2wy2xy 2wz w2 x2 +y2 z2 2yz + 2wx

    2xz+ 2wy 2yz 2wx w2 x2 y2 +z2

    as well as,

    2

    12 y2 z2 xy+wz xz wyxy wz 12 x2 z2 yz +wx

    xz+wy yz wx 12 x2 y2

    .

    It is also important to solve the problem of finding the quaternion associated with

    matrixLor R. We left this problem for the exercises at the end of the chapter.

    8.2 Quaternions and Eulers angles

    Another important relation is to obtain the quaternion associated with a rotation using

    Eulers angles and . We have three rotationsRx(),Ry(),Rz()of angles,,about axes(1, 0, 0),(0, 1, 0)and (0, 0, 1), respectively. Each one of these rotations isrepresented byqx ,qy , andqz , where

  • 7/23/2019 Rotations in Computer Graphics

    30/36

    30 CHAPTER 4: ROTATIONS

    qx = cos2

    + sin2

    (1, 0, 0),

    qy = cos

    2+ sin

    2(0, 1, 0),

    qz = cos

    2+ sin

    2(0, 0, 1).

    The rotation in space is given by Rz()Ry()Rx(), and it will be represented by thequaternionq = qzqyqx, obtained from the product of the three quaternions. Supposing

    q= w+ ix+jy+ kz,

    and doing the calculations, we obtain

    w= cos

    2cos

    2sin

    2+ sin

    2sin

    2sin

    2

    x= sin

    2cos

    2cos

    2 cos

    2sin

    2sin

    2

    y= cos

    2sin

    2cos

    2+ sin

    2cos

    2sin

    2

    z= cos

    2cos

    2sin

    2+ sin

    2sin

    2cos

    2.

    9 Comments and References

    Hamiltons goal on searching for quaternions consisted on discovering a multiplication

    structure, similar to the one of complex numbers, for the R3 and that could be used to

    represent rotations in space. He ended up discovering such structure for the R4. Today

    it is known this type of structure exists only in R2, R4 and R8.

    Quaternions were introduced in Computer Graphics in the article (Shoemake, 1985).

    They were already used in the area of Robotics.

    For more information about orthogonal transformations ofRn, and in particular, the

    demonstration of Eulers Theorem in its general form, we suggest (Lima, 1999).

    9.1 Additional Topics

    In this chapter we studied the special group SO(3)of rotations in space which consistsin just a part of the representation of rigid motions in space. The complete group, has

    dimension 6 (three degrees of freedom for rotations and three for translations), and iscalledspecial Euclidean group, denoted bySE(3). An appropriate representation of thisgroup involves the screw theory and the study of the Lie Groups of matrices. Complete

    material on these topics can be found in a good textbook in the area of Robotics.

  • 7/23/2019 Rotations in Computer Graphics

    31/36

    SECTION 10: EXERCISES 31

    Quaternions just represent the tip of the iceberg in the study of intrinsic operationsamong geometric objects, a topic covered in the area of Geometric Algebra.

    An important topic that we did not cover is the problem of interpolating the n rotationsrepresented by quaternions. From what we covered, this problem is equivalent to the study

    of interpolation curves (e.g. Bezier, Splines) in the sphereS3. Several works exist aboutit on the literature. This subject is also very important for the area of GIS (Geographic

    Information Systems). The interpolation of rotations using the structure of Lie Groups of

    matrices is an interesting topic. (Alexa, 2002), for instance, describes the interpolation

    of linear transformations using results from Lie Groups of matrices.

    10 Exercises

    1. Demonstrate Chasles Theorems: Every positive rigid motion inR3 can be obtained

    by a rotation about a r-axis, followed by a translation along r (this type of motion iscalledscrew).

    2. Describe a method to obtain the quaternion associated with matrixLorR(as definedin this chapter), in homogeneous coordinates.

    3. IfR : R3 R3 is a rotation, show thatR(u v) =R(u) R(v).4. Show there exists no multiplicative structure in R3 among the vectors, similar to

    quaternions (or to complex numbers). (Suggestion: use the transformation Lq or Rqdefined in the chapter, including the fact that a linear transformation in R3 has 1 realeingenvalue.)

    5. If(rij) is a matrix of order3 representing a rotation in R3, show that the Eulers

    angles of the parameterization given byRz()Ry()Rz()are determined by:

    = arctg2(

    r231+r232, r33);

    = arctg2( r23sin

    , r13sin

    );

    = arctg2( r32sin

    , r31sin

    ),

    wherearctg2(x, y)is the functionarctg(x/y)using the signal ofx and y to determinethe quadrant of the resulting angle.

    6. Consider the following problem: to implement an interactive interface to rotate anobject ofR3 about an axis, just using the mouse as input device. Two solutions exist inthe literature for this problem: theMetaballand thevirtual sphere.

    a) Describe the model of these two solutions;

  • 7/23/2019 Rotations in Computer Graphics

    32/36

    32 CHAPTER 4: ROTATIONS

    b) Compare the solutions and discuss the advantages and disadvantages of each one.

    7. Show if a quaternionq commutes with every pure quaternion, then q is real. Use

    this fact to show that

    q1 =q2 q1=q2,whereq is the representation of a rotation defined in (4.9).

    8. Ifp = cos +v sin is a unit quaternion, andtR, show thatqptq = (qpq)t.9. Ifq is a unit quaternion, anda, bR, show that:

    qaqb =qa+b e (qa)b =qab.

    10. The calculations below show that the product of quaternions is commutative:

    pq= exp(log(pq))

    = exp[log(p) + log(q)]

    = exp[log(q) + log(p)]

    = exp(log(q)) exp(log(p)) =qp.

    Where is the error?

    11. Show that, in the case in which quaternionq is not unitary, the matrix (4.19) of the

    transformationq is given by

    2

    |q|2

    |q|2

    2 y2 z2 xy+wz xz wy 0xy wz |q|22 x2 z2 yz+wx 0xz+wy yz wx |q|22 x2 y2 0

    0 0 0 |q|2

    2

    .

    12. Show that

    eu = cos +u sin ,

    substituting the expression ofuin the series of potencies of the exponential function

    ex =n=0

    xn

    n.

    13. Let

    R=

    r11 r12 r13r21 r22 r23

    r31 r32 r33

  • 7/23/2019 Rotations in Computer Graphics

    33/36

    SECTION 10: EXERCISES 33

    be a rotation matrix in R3

    . Show that the rotation axis is the vector

    v= 1

    sin (r32 r23.r13 r31, r21 r12).

    If the angle of rotation is different from and 0, then

    = arcos

    r11+r22+r33 1

    2

    .

    What happens if the rotation angle is very small? Describe a robust method to find the

    rotation axis (your method should include the cases for = 0and = ).

    14. Using the previous exercise, show that the matrix

    Ry(90)Rz(90) =0 0 11 0 0

    0 1 0

    represents a rotation of120 about the axis of the R3 space defined by the unit vector(1/

    3, 1/

    3, 1/

    3).

    15. Ifq(t)is a curve in the unit sphereS3, thenq(t) = v(t)q(t), where vrepresentsa pure quaternion associated with the vector v R3. (Suggestion: Do q(t+ s) =q(t+s)q(t)q(t)1, and useq(t) =dq(t+s)/dsin the points = 0.)

    16. Ifq is a unit quaternion, show that

    d

    dtqt =qt log(q).

    17. Show the veracity of the equalities below:

    a) slerp(p, q, t) =p(pq)t;

    b) slerp(p, q, t) = (pq)1tq;

    c) slerp(p, q, t) = (qp)tp;

    d) slerp(p, q, t) =q(qp)1tq.

    Then conclude thatslerp(p, q, t) = slerp(q, p, 1 t).18. Ifv = (x,y ,z)

    R3,v

    = 0, show the Jacobian matrixd expv of the exponential

    function in the pointv is given by

    s|v|x s|v|y svz c|v|2

    s|v|3

    x2 + s

    |v|

    c|v|2

    s|v|3

    xy

    c|v|2

    s|v|3

    xz

    c|v|2

    s|v|3

    xy

    c|v|2

    s|v|3

    y2 + s|v|

    c|v|2

    s|v|3

    yz

    c|v|2

    s|v|3

    xz

    c|v|2

    s|v|3

    yz

    c|v|2

    s|v|3

    z2 + s|v|

    ,

  • 7/23/2019 Rotations in Computer Graphics

    34/36

    34 CHAPTER 4: ROTATIONS

    wheres= sin |v| andc = cos |v|.19. Show the Jacobian matrix of the exponential function at the originv = (0, 0, 0)R3, is given by the matrix

    0 0 01 0 00 1 00 0 1

    .

    (Suggestion: use the expression of the previous exercise for v= 0, together with thedefinition of the derivative as a limit.)

    20. This exercise shows that the multiplication of two quaternions can be made with

    only 8 products instead of16 products as would be expected. Given two quaterniosq1= (x1, y1, z1, w1)andq2= (x2, y2, z2, w2), do

    a1= (x1 y1)(y2 z2) a5= (z1 x1)(x2 y2)a2= (w1+x1)(w2+x2) a6= (z1+x1)(x2+y2)

    a3= (w1 x1)(y2+z2) a7= (w1+y1)(w2 z2)a4= (z1+y1)(w2 x2) a8= (w1 y1)(w2+z2).

    Defines = a6+a7+a8 and t= (a5+s)/2. Show that

    q1q2= (a2+t

    s)1 + (a2+t

    s)i + (a3+t

    a8)j + (a4+t

    a7)k.

  • 7/23/2019 Rotations in Computer Graphics

    35/36

    Bibliography

    Alexa, Marc. 2002. Linear Combination of Transformations. ACM Transactions onGraphics,21(3), 380387.

    Lima, Elon L. 1999. lgebra Linear. (Terceira edio). Instituto de Matemtica Pura eAplicada, Rio de Janeiro: Coleo Matemtica Universitria.

    Shoemake, K. 1985 (July). Animating Rotation with Quaternion Curve. Pages 245254of: Computer Graphics (SIGGRAPH 85 Proceedings), vol. 19.

    ndice

    Euler

    angles of, 7

    Eulers angles, 7

    and quaternions, 29

    geodesic, 21

    interpolation

    geodesic, 24radial spherical, 24

    maximum circle, 21

    parameterization

    exponential, 22

    place, 10

    quaternions, 4, 14

    and Eulers angles, 29

    and matrices, 27

    and rotations, 16

    conjugated, 14

    rotation

    and quaternions, 16Eulers angles, 7

    in the space, 4

    matrix of Euler, 9

    on the plane, 2

    quaternions, 4

    representation by quaternions, 14

    straight line nodal, 7

    35

  • 7/23/2019 Rotations in Computer Graphics

    36/36

    36 INDEX

    yaw, pitch and roll, 8

    slerp, 24, 26

    yaw, pitch and roll, 8