transformations n.
Skip this Video
Loading SlideShow in 5 Seconds..
Transformations PowerPoint Presentation
Download Presentation

Loading in 2 Seconds...

play fullscreen
1 / 55

Transformations - PowerPoint PPT Presentation

  • Uploaded on

Transformations. Objectives. Understand how transformations work in 2D and 3D Understand the concept of homogenous coordinate system Understand scene graphs and hierarchical composition of transformations Get familiar with transformations in OpenGL and DirectX. Transformations.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
    Presentation Transcript
    1. Transformations

    2. Objectives • Understand how transformations work in 2D and 3D • Understand the concept of homogenous coordinate system • Understand scene graphs and hierarchical composition of transformations • Get familiar with transformations in OpenGL and DirectX

    3. Transformations • Transformations change 2D or 3D points and vectors, or change coordinate systems. • An object transformation alters the coordinates of each point on the object according to the same rule, leaving the underlying coordinate system fixed. • A coordinate transformation defines a new coordinate system in terms of the old one, then represents all of the object’s points in this new system. • Object transformations are easier to understand, so we will do them first.

    4. Transformations (2) • A (2D or 3D) transformation T( ) alters each point P into a new point Q using a specific formula or algorithm: Q= T(P).

    5. Transformations (3) • An arbitrary point P in the plane is mapped to Q. • Q is the image of P under the mapping T. • We transform an object by transforming each of its points, using the same function T() for each point. • The image of line L under T, for instance, consists of the images of all the individual points of L.

    6. Transformations (4) • Most mappings of interest are continuous, so the image of a straight line is still a connected curve of some shape, although it’s not necessarily a straight line. • Affine transformations, however, do preserve lines: the image under T of a straight line is also a straight line.

    7. Geometric Effects of Affine Transformations • Combinations of four elementary transformations: (a) a translation, (b) a scaling, (c) a rotation, and (d) a shear (all shown below).

    8. P’ P 2D Translations

    9. P’ P 2D Scaling from the origin

    10. y  P’(x’,y’) P(x,y) r r x 2D Rotation about the origin Recall the right-hand rule!

    11. 2D Rotation about the origin y P’(x’,y’) P(x,y) r  y r  x x

    12. 2D Rotation about the origin. Substituting for r : After all, these are just High-schools formulas! Given us:

    13. 2D Rotation about the origin. Rewriting in matrix form gives us :

    14. Shear: Off Diagonal Elements

    15. Example 1 S

    16. Example 1 S

    17. Example 1 T(S)

    18. Example 2 S

    19. Example 2 S

    20. T(S) Example 2

    21. Summary Shear in x: Shear in y:

    22. Sample Points: unit inverses

    23. Geometric View of Shear in x

    24. Another Geometric View of Shear in x 24

    25. Another Geometric View of Shear in x 25

    26. Geometric View of Shear in y

    27. Another Geometric View of Shear in y h h 27

    28. Another Geometric View of Shear in y 28

    29. Transformations • Translation. • P=T + P • Scale • P=S  P • Rotation • P=R  P • Shear • P=H P • We would like all transformations to be multiplications so we can concatenate them  express points in homogenous coordinates.

    30. Homogeneous coordinates • Add an extra coordinate, W, to a point. • P(x,y,W). • Two sets of homogeneous coordinates represent the same point if they are a multiple of each other. • (2,5,3) and (4,10,6) represent the same point. • At least one component must be non-zero  (0,0,0) is not allowed. • If W 0 , divide by it to get Cartesian coordinates of point (x/W,y/W,1). • If W=0, point is said to be at infinity. • P(x,y,0) can be interpreted as the vector v(x, y) • Both points and vectors are represented by the same set of underlying objects

    31. W P W=1 plane X Y Homogeneous coordinates • If we represent (x,y,W) in 3-space, all triples representing the same point describe a line passing through the origin. • If we homogenize the point, we get a point of form (x,y,1) • homogenised points form a plane at W=1.

    32. Translations in homogenised coordinates • Transformation matrices for 2D translation are now 3x3.

    33. Concatenation • We perform 2 translations on the same point:

    34. Concatenation. Matrix product is variously referred to as compounding, concatenation, or composition. This single matrix is called the Coordinate Transformation Matrix or CTM.

    35. Homogeneous form of scale Recall the (x,y) form of Scale : In homogeneous coordinates :

    36. Concatenation of scales.

    37. Homogeneous form of rotation

    38. Composition of Transformations • Suppose we want to rotate around an arbitrary point P • Idea: Compose simple transformations 1. Translate P to origin 2. Rotate around origin 3. Translate origin back to P The order is very important!

    39. Order!

    40. y Note: Convenient to think of display as Being left-handed !! ( z into the screen ) x z (out of page) 3D Transformations • Use homogeneous coordinates, just as in 2D case. • Transformations are now 4x4 matrices. • We will use a right-handed (world) coordinate system - ( z out of page ).

    41. More on Homogeneous Coordinates • To: if the object is a vector, add a 0 as the 4th coordinate; if it is a point, add a 1. • From: • If the 4th coordinate is zero, then simply remove it. • If it is not, then divide the other coordinate by it and remove it. • OpenGL uses 4D homogeneous coordinates for all its vertices. • If you send it a 3-tuple in the form (x, y, z), it converts it immediately to (x, y, z, 1). • If you send it a 2D point (x, y), it first appends a 0 for the z-component and then a 1, to form (x, y, 0, 1). • All computations are done within OpenGL in 4D homogeneous coordinates.

    42. Combinations • Linear combinations of vectors and points: • The difference of 2 points is a vector: the fourth component is 1 – 1 = 0 • The sum of a point and a vector is a point: the fourth component is 1 + 0 = 1 • The sum of 2 vectors is a vector: 0 + 0 = 0 • A vector multiplied by a scalar is still a vector • Linear combinations of vectors are vectors

    43. Translation in 3D Simple extension to the 3D case: • In OpenGL: • glMatrixMode(GL_ModelView); • glTranslatef(dx, dy, dz); • In DirectX: • device.Transform.World = Matrix.Translation(dx, dy, dz)

    44. Scale in 3D Simple extension to the 3D case: • In OpenGL: • glMatrixMode(GL_ModelView); • glScalef(Sx, Sy, Sz); • In DirectX: • device.Transform.World = Matrix.Scaling(Sx, Sy, Sz)

    45. Rotation in 3D • Need to specify which axis the rotation is about. • z-axis rotation is the same as the 2D case. • In OpenGL: • glMatrixMode(GL_ModelView); • glRotatef(theta, 0.0f, 0.0f, 1.0f); • In DirectX: • device.Transform.World = Matrix.RotationZ(theta)

    46. Rotation in 3D • For rotation about the x and y axes: • In OpenGL: • glMatrixMode(GL_ModelView); • glRotatef(theta, 1.0f, 0.0f, 0.0f); • //gRotatef(theta,0.0f,1.0f,0.0f) (about y) • In DirectX: • device.Transform.World = Matrix.RotationZ(theta); • //Matrix.RotationY(theta) (about y)

    47. Transformations of coordinate systems • Alternate view: when we apply a transformation, we’re not changing the coordinates of a point within a coordinate system. Instead, we’re changing the coordinate system itself • All the transformations are performed relative to the current coordinate frame origin and axes; OpenGL post-multiplies each new transformation matrix

    48. M1 M2 C1 C2 C3 (a3,b3) C3 a3 b3 C1 C2 M2 M1 Successive Transformations Given P (a3,b3) in C3 What is P’s coordinates in C1? • Get P’s coordinates in C2 • P_c2 = M2 x P • Get P_c2’s coordinates in C1 • P_c1 = M1 x P_c2 • P_c1 = M1 x M2 x P the answer!!

    49. Successive Transformations (2) • The sequence translate 1.5 0 0cube translate 8.5 0 0cubewill draw two cubes with x centres 1.5 and 10.0 respectively. • We could create the same image with the sequence save state translate 1.5 0 0cube restore state save state translate 10.0 0 0cube restore state • Here both cubes have an absolute translation and the order in which the two cubes are drawn does not matter.

    50. Hierarchical composition using Push and Pop • glPushMatrix(); • Save the state. • Push a copy of the CTM onto the stack. • The CTM itself is unchanged. • glPopMatrix(); • Restore the state, as it was at the last Push. • Overwrite the CTM with the matrix at the top of the stack. • glLoadIdentity(); • Overwrite the CTM with the identity matrix.