Presentation is loading. Please wait.

Presentation is loading. Please wait.

2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.

Similar presentations


Presentation on theme: "2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together."— Presentation transcript:

1 2D Transformations

2 World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together

3 Transformations Rigid Body Transformations - transformations that do not change the object. Translate –If you translate a rectangle, it is still a rectangle Scale –If you scale a rectangle, it is still a rectangle Rotate –If you rotate a rectangle, it is still a rectangle

4 Vertices We have always represented vertices as (x,y) An alternate method is: Example:

5 Matrix * Vector

6 Matrix * Matrix Does A*B = B*A? NO What does the identity do? AI=A

7 Translation Translation - repositioning an object along a straight-line path (the translation distance) from one coordinate location to another. (x,y)(x,y) (x’,y’) (t x,t y )

8 Translation Given: We want: Matrix form:

9 Translation Examples P=(2,4), T=(-1,14), P’=(?,?) P=(8.6,-1), T=(0.4,-0.2), P’=(?,?) P=(0,0), T=(1,0), P’=(?,?)

10 Recall A point is a position specified with coordinate values in some reference frame. We usually label a point in this reference point as the origin. All points in the reference frame are given with respect to the origin.

11 Applying to Triangles (t x,t y )

12 What do we have here? You know how to:

13 Scale Scale - Alters the size of an object. Scales about a fixed point (x,y)(x,y) (x’,y’)

14 Scale Given: We want: Matrix form:

15 Non-Uniform Scale (x,y)(x,y) (x’,y’) S=(1,2)

16 Rotation Rotation - repositions an object along a circular path. Rotation requires an  and a pivot point 

17 Rotation

18 Example P=(4,4)  =45 degrees

19 Rotations V(-0.6,0) V(0,-0.6) V(0.6,0.6) Rotate -30 degrees V(0,0.6) V(0.3,0.9) V(0,1.2)

20 Combining Transformations Q: How do we specify each transformation?

21 Specifying 2D Transformations Translation –T(t x, t y ) –Translation distances Scale –S(s x,s y ) –Scale factors Rotation –R(  ) –Rotation angle

22 Combining Transformations Using translate, rotation, and scale, how do we get:

23 Combining Transformations Note there are two ways to combine rotation and translation. Why?

24 Let’s look at the equations

25 Combining them We must do each step in turn. First we rotate the points, then we translate, etc. Since we can represent the transformations by matrices, why don’t we just combine them?

26 2x2 -> 3x3 Matrices We can combine transformations by expanding from 2x2 to 3x3 matrices.

27 Homogenous Coordinates We need to do something to the vertices By increasing the dimensionality of the problem we can transform the addition component of Translation into multiplication.

28 Homogenous Coordinates Homogenous Coordinates - term used in mathematics to refer to the effect of this representation on Cartesian equations. Converting a pt(x,y) and f(x,y)=0 -> (x h,y h,h) then in homogenous equations mean (v*x h,v*y h,v*h) can be factored out. What you should get: By expressing the transformations with homogenous equations and coordinates, all transformations can be expressed as matrix multiplications.

29 Final Transformations - Compare Equations

30 Combining Transformations

31 How would we get:

32

33 Coordinate Systems Object Coordinates World Coordinates Eye Coordinates

34 Object Coordinates

35 World Coordinates

36 Screen Coordinates

37 Coordinate Hierarchy

38 Let’s reexamine assignment 1

39 Transformation Hierarchies (See chapter 10 for details) For example, a robot arm

40 Transformation Hierarchies Let’s examine:

41 Transformation Hierarchies What is a better way?

42 Transformation Hierarchies What is a better way?

43 Transformation Hierarchies We can have transformations be in relation to each other World Coordinates Upper Arm Coordinates Lower Arm Coordinates Hand Coordinates Transformation: Upper Arm -> World Transformation: Lower -> Upper Transformation: Hand-> Lower

44 44 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rotation about a Fixed Point Start with identity matrix: C  I Move fixed point to origin: C  CT Rotate: C  CR Move fixed point back: C  CT -1 Result: C = TR T –1 which is backwards – Cp This result is a consequence of doing postmultiplications. Let’s try again.

45 45 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Reversing the Order We want C = T –1 R T so we must do the operations in the following order C  I C  CT -1 C  CR C  CT Each operation corresponds to one function call in the program. Note that the last operation specified is the first executed in the program

46 46 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Example Rotation about z axis by 30 degrees with a fixed point of (1.0, 2.0, 3.0) Remember that last transform specified in the program is the first applied glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(1.0, 2.0, 3.0); glRotatef(30.0, 0.0, 0.0, 1.0); glTranslatef(-1.0, -2.0, -3.0); glBegin(GL_TRIANGLES);...

47 47 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Matrix Stacks In many situations we want to save transformation matrices for use later –Traversing hierarchical data structures (Chapter 10) –Avoiding state changes when executing display lists OpenGL maintains stacks for each type of matrix –Access present type (as set by glMatrixMode) by glPushMatrix() glPopMatrix()


Download ppt "2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together."

Similar presentations


Ads by Google