2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2...

13
2003 CS Hons RW778 Graphics 1 Chapter 5: Chapter 5: Transforming Objects Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations Affine transformations are useful: Affine transformations are useful: » Compose scene from instances Compose scene from instances » Exploit and repeat symmetries Exploit and repeat symmetries » Different viewpoints of same scene (move camera) Different viewpoints of same scene (move camera) » Computer animation Computer animation Graphics pipeline and current transformation (CT) Graphics pipeline and current transformation (CT) Object transformation vs coordinate transformation Object transformation vs coordinate transformation

Transcript of 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2...

Page 1: 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations –Affine transformations.

2003 CS Hons RW778 Graphics 1

Chapter 5: Transforming ObjectsChapter 5: Transforming Objects

5.2 Introduction to Transformations5.2 Introduction to Transformations– Affine transformations are useful:Affine transformations are useful:

» Compose scene from instancesCompose scene from instances

» Exploit and repeat symmetriesExploit and repeat symmetries

» Different viewpoints of same scene (move camera)Different viewpoints of same scene (move camera)

» Computer animationComputer animation

– Graphics pipeline and current transformation (CT)Graphics pipeline and current transformation (CT)

– Object transformation vs coordinate transformationObject transformation vs coordinate transformation

Page 2: 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations –Affine transformations.

2003 CS Hons RW778 Graphics 2

Chapter 5: Transforming ObjectsChapter 5: Transforming Objects

5.2.1 Transforming Points and Objects5.2.1 Transforming Points and Objects– Map point P to image QMap point P to image Q– Most mappings continuousMost mappings continuous– Restrict ourselves to affine (linear) transformations.Restrict ourselves to affine (linear) transformations.

5.2.2 The Affine Transformations5.2.2 The Affine Transformations

– and similarly for vectors.and similarly for vectors.

1

P

P

1

m

m

0

m

m

0

m

m

1

Q

Q

y

x

23

13

22

12

21

11

y

x

Page 3: 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations –Affine transformations.

2003 CS Hons RW778 Graphics 3

Chapter 5: Transforming ObjectsChapter 5: Transforming Objects

5.2.3 Geometric Effects of Elementary 2D Affine 5.2.3 Geometric Effects of Elementary 2D Affine TransformationsTransformations– Combinations of : Translation, scaling, rotation, shear.Combinations of : Translation, scaling, rotation, shear.– Translation:Translation:

» Or, Q = P + Or, Q = P + dd

– Scaling:Scaling:» scaling about the originscaling about the origin» negative: reflectionnegative: reflection» uniform vs differential scalinguniform vs differential scaling

1

P

P

1

m

m

0

1

0

0

0

1

1

Q

Q

y

x

23

13

y

x

1

P

P

1

0

0

0

S

0

0

0

S

1

Q

Q

y

x

y

x

y

x

Page 4: 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations –Affine transformations.

2003 CS Hons RW778 Graphics 4

Chapter 5: Transforming ObjectsChapter 5: Transforming Objects

– Rotation: CCW Rotation: CCW

– Shearing:Shearing:

1

P

P

1

0

0

0

)cos(

)sin(

0

)sin(

)cos(

1

Q

Q

y

x

y

x

1

P

P

1

0

0

0

1

h

0

0

1

1

Q

Q

y

x

y

x

Page 5: 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations –Affine transformations.

2003 CS Hons RW778 Graphics 5

Chapter 5: Transforming ObjectsChapter 5: Transforming Objects

5.2.4 Inverse of an Affine Transformation5.2.4 Inverse of an Affine Transformation– Most affine transformations are nonsingular (ie det(M) Most affine transformations are nonsingular (ie det(M)

is nonzero)is nonzero)– To undo transformation Q = MP, use P = MTo undo transformation Q = MP, use P = M-1-1Q.Q.– Scaling:Scaling:

– Rotation:Rotation:

– Shearing:Shearing:

– Translation:Translation:

1

P

P

1

0

0

0

1

h

0

0

1

1

Q

Q

y

x

y

x

1

P

P

1

0

0

0

S/1

0

0

0

S/1

1

Q

Q

y

x

y

x

y

x

1

P

P

1

0

0

0

)cos(

)sin(

0

)sin(

)cos(

1

Q

Q

y

x

y

x

1

P

P

1

m

m

0

1

0

0

0

1

1

Q

Q

y

x

23

13

y

x

Page 6: 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations –Affine transformations.

2003 CS Hons RW778 Graphics 6

Chapter 5: Transforming ObjectsChapter 5: Transforming Objects

5.2.5 Composing Affine Transformations5.2.5 Composing Affine Transformations– For homogeneous coordinates: Affine transformations For homogeneous coordinates: Affine transformations

composed by matrix multiplication in reverse order.composed by matrix multiplication in reverse order.

5.2.6 Examples: Composing 2D Transformations5.2.6 Examples: Composing 2D Transformations– Rotate about an arbitrary point: translate, rotate, Rotate about an arbitrary point: translate, rotate,

translatetranslate

– Reflections about a tilted lineReflections about a tilted line

Page 7: 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations –Affine transformations.

2003 CS Hons RW778 Graphics 7

Chapter 5: Transforming ObjectsChapter 5: Transforming Objects

5.2.7 Useful Properties of Affine Transformations5.2.7 Useful Properties of Affine Transformations– AT preserve affine combinations of pointsAT preserve affine combinations of points

T(aT(a11PP11+a+a22PP22) = a) = a11T(PT(P11) + a) + a22T(PT(P22))– AT preserve lines and planes: If L(t)=(1-t)A+tB, thenAT preserve lines and planes: If L(t)=(1-t)A+tB, then

Q(t) = (1-t)T(A) + tT(B)Q(t) = (1-t)T(A) + tT(B)– Parallelism of lines and planes is preserved: Given Parallelism of lines and planes is preserved: Given

A+A+bbt, we have M(A+t, we have M(A+bbt)=MA + (Mt)=MA + (Mbb)t. Independent of )t. Independent of A, with same direction A, with same direction bb..

– Columns of matrix reveal transformed coordinate frameColumns of matrix reveal transformed coordinate frame» mm11=M=Mii, , mm22=M=Mj j » Frame (Frame (ii,,jj,,) transforms into frame () transforms into frame (mm11,,mm22,m,m33))

Page 8: 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations –Affine transformations.

2003 CS Hons RW778 Graphics 8

Chapter 5: Transforming ObjectsChapter 5: Transforming Objects

– Relative ratios are preserved:Relative ratios are preserved:

– Effects of transformations on areas:Effects of transformations on areas:|det M| = |det M| =

– Every AT is composed of elementary operations:Every AT is composed of elementary operations:» 2D:any M can be written as (translation)(shear)(scale)2D:any M can be written as (translation)(shear)(scale)

(rotation)(rotation)

» 3D:any M as (transl)(scale)(rotation)(shear1)(shear2)3D:any M as (transl)(scale)(rotation)(shear1)(shear2)

ation transformbefore area

sformationafter tran area

Page 9: 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations –Affine transformations.

2003 CS Hons RW778 Graphics 9

Chapter 5: Transforming ObjectsChapter 5: Transforming Objects

5.3 3D Affine Transformations5.3 3D Affine Transformations– 5.3.1 Elementary 3D Transformations5.3.1 Elementary 3D Transformations

» As for 2D. As for 2D. Selfstudy pp. 234-238Selfstudy pp. 234-238..Note rotations: x-roll, y-roll, z-roll.Note rotations: x-roll, y-roll, z-roll.

– 5.3.2 Composing 3D Affine Transformations5.3.2 Composing 3D Affine Transformations» As for 2D. As for 2D. Selfstudy p. 238Selfstudy p. 238..

– 5.3.3 Combining rotations5.3.3 Combining rotations» 3D rotation matrices do not commute!3D rotation matrices do not commute!

» M = RM = Rzz((ßß33)R)Ryy(ß(ß22)R)Rxx(ß(ß11) : Euler’s angles) : Euler’s angles

Page 10: 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations –Affine transformations.

2003 CS Hons RW778 Graphics 10

Chapter 5: Transforming ObjectsChapter 5: Transforming Objects

– Rotations about arbitrary axis: Rotations about arbitrary axis: » Any rotation about a point is equivalent to a single rotation Any rotation about a point is equivalent to a single rotation

about some axis through the point (Euler’s theorem).about some axis through the point (Euler’s theorem).

» RRuu(ß) = R(ß) = Ryy(-(-)R)Rzz(()R)Rxx(ß)R(ß)Rzz(()R)Ryy(())

» OpenGL: OpenGL: glRotated (angle, ux, uy, uz)glRotated (angle, ux, uy, uz)

Page 11: 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations –Affine transformations.

2003 CS Hons RW778 Graphics 11

Chapter 5: Transforming ObjectsChapter 5: Transforming Objects

– Finding axis and angle of rotation: Finding axis and angle of rotation: ReadRead..

5.4 Changing Coordinate Systems5.4 Changing Coordinate Systems– (a,b,1)(a,b,1)TT = M(c,d,1) = M(c,d,1)TT

– Successive changes in coordinate frame:Successive changes in coordinate frame: (a,b,1) (a,b,1)TT = M = M11(c,d,1)(c,d,1)T T = M= M11MM22(e,f,1)(e,f,1)TT

– Note: to transform points, premultiply.Note: to transform points, premultiply.To transform coordinate system, postmultiply.To transform coordinate system, postmultiply.

– OpenGL: postmultiply by default.OpenGL: postmultiply by default.

Page 12: 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations –Affine transformations.

2003 CS Hons RW778 Graphics 12

Chapter 5: Transforming ObjectsChapter 5: Transforming Objects

– Finding axis and angle of rotation: Finding axis and angle of rotation: ReadRead..

5.5 Affine Transformations in a Program5.5 Affine Transformations in a ProgramSelfstudy.Selfstudy.

5.6 Drawing 3D Scenes with OpenGL5.6 Drawing 3D Scenes with OpenGLSelfstudySelfstudy. Note : . Note : modelview matrix,modelview matrix,

projection matrix,projection matrix,

viewport matrix.viewport matrix.

Page 13: 2003CS Hons RW778 Graphics1 Chapter 5: Transforming Objects 5.2 Introduction to Transformations 5.2 Introduction to Transformations –Affine transformations.

2003 CS Hons RW778 Graphics 13

Chapter 5: Transforming ObjectsChapter 5: Transforming Objects

Homework Task 4Homework Task 4 : :1.1. Practice Exercise 5.2.6, p. 223.Practice Exercise 5.2.6, p. 223.

2.2. Practice Exercise 5.2.21, pp. 228.Practice Exercise 5.2.21, pp. 228.

3.3. Practice Exercise 5.3.9, p. 243.Practice Exercise 5.3.9, p. 243.

4.4. Practice Exercise 5.5.3, p. 258.Practice Exercise 5.5.3, p. 258.

5.5. Practice Exercise 5.6.1, p. 264.Practice Exercise 5.6.1, p. 264.

6.6. Practice Exercise 5.8.10, p. 283.Practice Exercise 5.8.10, p. 283.