• Aucun résultat trouvé

Quaternions and In-betweening

Dans le document Computer Graphics and Geometric Modeling (Page 162-168)

This short section describes another aspect of how transformations get used in ani-mation. In particular, we discuss a nice application of quaternions. Unit quaternions are a more efficient way to represent a rotation of R3 than the standard matrix rep-resentation of SO(3). Chapter 20 provides the mathematical foundation for quater-nions. Other references for the topic of this section are [WatW92], [Hogg92], and [Shoe93].

We recall some basic facts about the correspondence between rotations about the origin in R3 and unit quaternions. First of all, the quaternion algebra H is just R4 endowed with the quaternion product. The metric on H is the same as that on R4. The standard basis vectors e1,e2,e3,e4are now denoted by 1,i,j,k, respectively. The subspace generated by i, j, and k is identified with R3 by mapping the quaternion ai+bj+ck to (a,b,c) and vice versa. The rotation R of R3 through angle q about the directed line through the origin with unit direction vector nis mapped to the quater-nionqdefined by

then MqŒSO(3) and the map of R3that sends ptopMqis a rotation Rqabout the line through the origin with direction vector nthrough the angle 2q. This mapping

has the property that Rq=R-q.

Now, suppose an object is moved by a one-parameter family of matrices M(s) ΠSO(3). Assume that we have only specified this family at a fixed set of values si. How can we interpolate between these values? In animation such an interpolation is called in-betweening. A simple interpolation of the form

would not work because the interpolants would not again be elements of SO(3). One could try to use Euler angles, but there are problems with this also. See [Shoe85]. A better way is to translate our maps into quaternions and to look for a one-parameter family of unit quaternions q(s) that interpolates between two quaternions a and b.

However, a simple linear interpolation followed by a normalization to get unit quater-nions does not work well either for the same reason that one does not get a uniform subdivision of an arc of a circle by centrally projecting a uniform subdivision of the chord connecting its endpoints. What would happen in the animation is that the object would move faster in the middle of the interpolation. A better solution is to subdivide the arc of the great circle in S3connectingaandb. See Figure 4.26.

4.14.1 Lemma. Letaand b be two unit quaternions that make an angle of q π 0 with each other, that is, a·b=cosqand 0 < q < p. Then the unit quaternion c(t) that lies in the plane spanned by aandb and which makes an angle tqwitha, 0 £t£1 is defined by the equation

(4.28) Proof. By hypothesis,

c( )t =ra+sb

ct t a t b

( )= ( - ) sin +

sin

sin sin . 1 q

q

q q tM s( )i +(1-t M s) ( i+1)

unit quaternions rotations of about the origin R

Æ Æ

R

q q

3

Figure 4.26. Interpolating between two quaternions.

for some real numbers r and s. Taking the dot product of both sides of this equation withaandbleads to equations

(4.29) and

(4.30) Solving equations (4.29) and (4.30) for r and s and using some standard trigonomet-ric identities leads to the stated result.

4.14.2 Example. LetL0andL1be the positively directed x- and y-axis, respectively.

Let R0and R1be the rotations about the directed lines L0andL1, respectively, through angle p/3 and let M0 and M1be the matrices that represent them. If Mt, t Œ[0,1], is the 1-parameter family of in-betweening matrices in SO(3) between M0and M1, then what is M1/2?

Solution. The unit direction vectors for L0andL1aren0=(1,0,0) and n1=(0,1,0), respectively. Therefore, by equation (4.25)

and

are the unit quaternions corresponding to rotation R0 and R1. The angle qbetween q0andq1is defined by

We can also see from the expression for q1/2and equation (4.26) that M1/2defines a rotation about the directed line through the origin with direction vector (1,1,0) and angle 2a, where

It is clear that the quaternions c(t) defined by Lemma 4.14.1 do indeed lie on a great circles in the unit sphere of the quaternions. We have solved the uniform spacing problem, but unfortunately this is not the end of the story as far as animation is con-cerned. Two points on a circle divide the circle into two arcs. If the points are not antipodal points, then one typically is interested in the smaller arc. In our situation we cannot simply always take the smaller arc without further consideration because we are representing rotations by quaternions, and if q is a unit quaternion, both q and-qcorrespond to the same rotation in SO(3). The solution suggested in [WatW92]

is, given representations aandbfor two rotations, to choose between a,banda,-b.

One compares the distance between aand b, |a -b|, to the distance between aand -b, |a+b|. If the former is smaller use a,botherwise use a,-b.

After getting our uniformly spaced quaternions c(ti) along the arc, if we were to do a linear interpolation between them, then the motion may look jerky. It is better to smooth things out by using Bezier curves or, more generally, splines, but this is somewhat more complicated in quaternion space than it was in Rn. See [BCGH92], [WatW92], [Hogg92], or [Shoe93] for what needs to be done.

4.15 Conclusions

Transformations were at the center of all the discussions in this chapter. We would like to emphasize one last time that when it comes to representing and defining affine transformations one should do that via frames if at all possible. Frames are ortho-normal basis and these are easy to define. Without them, geometric modeling for n-dimensional objects would become very complicated when n is larger than 2. Once one has a frame it can be interpreted as a transformation, a coordinate system, or as defining a change of coordinates. See Chapter 2 in [AgoM05] for more details.

The main role of homogeneous coordinates and projective space is as the natural setting for projective transformations. The mathematics becomes much easier. A prac-tical application is that one can replace all transformations, including translations, with matrices in uniform way. We described some of the main perspective and par-allel projections.

The discussion in this chapter emphasized a mathematical view of transforma-tions. Let us add a few comments about efficiency because there are times when effi-ciency is more important than clarity. Transformations get used a lot in geometric modeling and generating them in a systematic way, which usually involves repre-senting them as a composite of primitive ones, involves more arithmetic operations than necessary. The papers [Gold90] and [Mill99] describe a more efficient approach.

For example, suppose we express an arbitrary affine transformation T of R3 in the form

where M is a 3 ¥3 matrix and vis a fixed translation vector. If T is a rotation through an angle qabout a line Lthrough a point qwith direction vector w, then it is shown that

(4.31a) (4.31b) where I is the 3 ¥3 identity matrix,

and

With this representation, an optimized computation takes 15 multiplications and 10 additions to compute M and 9 multiplications and 9 additions to compute v. The number of operations to compute the matrix M and vector vwith the “composite-of-transformations” approach would be much greater. See [Gold90] for efficient formu-las for other transformations.

Finally, one topic not discussed much in this book (other than in the documen-tation for the GM and SPACE program) is the user interface of a modeling program, even though this takes up a large percentage of the time needed to develop such a program in general. Certain aspects of such a discussion, if we had the space or time, would probably be most appropriate in the context of the topic of this chapter. There are lots of interesting issues here as to how one can make it easier for the user to define the desired view of the world. How to best look at the world is often a major concern to a user. How does a user specify a view? How does one control panning and zooming? How does one specify a user’s or the camera’s arbitrary movement through the world? In a three-dimensional world this is not always easy if all one has is a keyboard and a mouse.

A

4.16 E

XERCISES Section 4.2

4.2.1 Prove equation (4.3).

4.2.2 Find the world-to-camera coordinates transformation T in two dimensions given the following data: the camera is at (1,4) looking in direction (-1,-3) with the view “plane”

(a line) a distance in front of the camera.

4.2.3 Find the world-to-camera coordinates transformation T in three dimensions given that the camera is at (2,3,5) looking in direction (-1,2,1) with the view plane a distance 7 in front of the camera.

Section 4.3

4.3.1 A camera is situated at the origin looking in direction v. Find the vanishing points of the view defined by lines parallel to the standard unit cube when

(a) v=(2,0,3) (b) v=(0,3,0) (c) v=(3,1,2)

Section 4.5

4.5.1 With regard to Figure 4.11 show that the regions below are mapped as indicated:

Note that z/w denotes the “real” z coordinate of a projective point (x,y,z,w).

4.5.2 Assume that the near and far planes for a camera are z =2 and z =51, respectively, in camera coordinates. If the view plane is z =5, find the matrix MhcamÆhclip.

Section 4.7

4.7.1 Explain how the case (0,0,0,0) can occur.

Section 4.9

4.9.1 Prove Proposition 4.9.1.

4.9.2 Compute the parallel projection of R3onto the x-y plane in the direction v=(2,1,5).

4.9.3 Compute the parallel projection of R3 onto the plane x - 2y+ 3z =1 in the direction v=(2,1,-3).

-• < < - Æ < < +•

- < < Æ -• < <

< < +• Æ < < +

z w z w

z w z w

z w z w

1 1

1 0 0

0 0 1

10

Section 4.14

4.14.1 Let L0 andL1 be the directed lines through the origin in R3 with direction vectors (1,-1,0) and (1,1,0), respectively. Let R0and R1be the rotations about the directed lines L0andL1, respectively, through angle p/3 and let M0and M1be the matrices that rep-resent them. If Mt, t Œ[0,1], is the 1-parameter family of in-betweening matrices in SO(3) between M0and M1, find M1/2?

Section 4.15

4.15.1 Show that equations (4.31) compute the rotation T correctly.

4.17 P

ROGRAMMING

P

ROJECTS

Dans le document Computer Graphics and Geometric Modeling (Page 162-168)