Presentation is loading. Please wait.

Presentation is loading. Please wait.

C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.

Similar presentations


Presentation on theme: "C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6."— Presentation transcript:

1 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6

2 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 2/29 Announcement Proj 1 posted on 2/2, due two weeks from today.

3 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 3/29 Translate [1,3] by [7,9] Scale [2,3] by 5 in the X direction and 10 in the Y direction Rotate [2,2] by 90 ° ( π /2) What is the result for each of the following two cases applied to the house in the figure. Exercises Case 1: Translate by x=6, y=0 then rotate by 45º 0 1 1 2 2 3 4 5 6 7 8 9 10 3 4 5 6 Case 2: Rotate by 45 and then translate by x=6, y=0

4 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 4/29 Translate [1,3] by [7,9] Scale [2,3] by 5 in the X direction and 10 in the Y direction Rotate [2,2] by 90 ° ( π /2) Examples

5 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 5/29 Scene graph (DAG) construction from primitives Object motion (this lecture) Camera motion (next lecture on viewing) ROBOT transformation upper bodylower body headtrunkarm base Scenegraph (see Sceneview assignment) stanchion “is composed of hierarchy” Why do we need geometric Transformations (T,R,S) in Graphics? More on scenegraphs on Slide 18

6 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 6/29 2D Transformations

7 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 7/29 Component-wise addition of vectors v’ = v + t where and x’ = x + dx y’ = y + dy To move polygons: translate vertices (vectors) and redraw lines between them Preserves lengths (isometric) Preserves angles (conformal) Translation is thus "rigid-body" dx = 2 dy = 3 Y X 0 1 1 2 2 3 4 5 6 7 8 9 10 3 4 5 6 Side effect: House shifts position relative to origin 2D Translation (Points designate origin of object's local coordinate system)

8 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 8/29 Component-wise scalar multiplication of vectors v’ = Sv where and Does not preserve lengths Does not preserve angles (except when scaling is uniform) 2D Scaling Side effect: House shifts position relative to origin

9 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 9/29 v’ = R θ v where and x’ = x cos Ө – y sin Ө y’ = x sin Ө + y cos Ө A rotation by 0 angle, i.e. no rotation at all, gives us the identity matrix Preserves lengths in objects, and angles between parts of objects Rotation is rigid-body Y X 0 1 1 2 2 3 4 5 6 7 8 9 10 3 4 5 6 2D Rotation Side effect: House shifts position relative to origin Rotate by  about the origin

10 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 10/29 Suppose object is not centered at origin and we want to scale and rotate it. Solution: move to the origin, scale and/or rotate in its local coordinate system, then move it back. This sequence suggests the need to compose successive transformations… 2D Rotation and Scale are Relative to Origin Object’s local coordinate system origin

11 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 11/29 Translation, scaling and rotation are expressed as: Composition is difficult to express – translation is not expressed as a matrix multiplication Homogeneous coordinates allows expression of all three transformations as 3x3 matrices for easy composition w is 1 for affine transformations in graphics Note: This conversion does not transform p. It is only changing notation to show it can be viewed as a point on w = 1 hyperplane translation: scale: rotation: v’ = v + t v’ = Sv v’ = Rv Homogenous Coordinates becomes

12 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 12/29 For points written in homogeneous coordinates, translation, scaling and rotation relative to the origin are expressed homogeneously as: 2D Homogeneous Coordinate Transformations

13 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 13/29 Avoiding unwanted translation when scaling or rotating an object not centered at origin: – translate object to origin, perform scale or rotate, translate back. How would you scale the house by 2 in “its” y and rotate it through 90° ? Remember: matrix multiplication is not commutative! Hence order matters! (Refer to class website: resources/SIGGRAPH2001_courseNotes_source/tr ansformation for camera transformation) Matrix Compositions: Using Translation

14 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 14/29 Matrix Multiplication is NOT Commutative Translate by x=6, y=0 then rotate by 45º Rotate by 45º then translate by x=6, y=0 0 1 1 2 2 3 4 5 6 7 8 9 10 3 4 5 6 Y X 0 1 1 2 2 3 4 5 6 7 8 9 3 4 5 6

15 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 15/29 3D Transformations

16 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 16/29 Translation Scaling (right-handed coordinate system) x y z 3D Basic Transformations (1/2)

17 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 17/29 Rotation about X-axis (right-handed coordinate system) Rotation about Y-axis Rotation about Z-axis 3D Basic Transformations (2/2)

18 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 18/29 More transformation matrices

19 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 19/29 “Skew” a scene to the side: Squares become parallelograms - x coordinates skew to right, y coordinates stay same Degree between axes becomes Ө Like pushing top of deck of cards to the side – each card shifts relative to the one below Notice that the base of the house (at y=1) remains horizontal, but shifts to the right. Y X 0 1 1 2 2 3 4 5 6 7 8 9 10 3 4 5 6 NB: A skew of 0 angle, i.e. no skew at all, gives us the identity matrix, as it should Skew/Shear/Translate (1/2) 2D non-homogeneous 2D homogeneous

20 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 20/29 Scene graph manipulation

21 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 21/29 3D scenes are often stored in a scene graph: – Open Scene Graph – Sun’s Java3D™ – X3D ™ (VRML ™ was a precursor to X3D) Typical scene graph format: – objects (cubes, sphere, cone, polyhedra etc.) – stored as nodes (default: unit size at origin) – attributes (color, texture map, etc.) and transformations are also nodes in scene graph (labeled edges on slide 2 are an abstraction) Transformations in Scene Graphs (1/3)

22 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 22/29 ROBOT upper bodylower body headtrunk arm stanchion base 1. Leaves of tree are standard size object primitives 2. We transform them 3. To make sub-groups 4. Transform subgroups 5. To get final scene Closer look at Scenegraph from slide 2 … Transformations in Scene Graphs (2/3)

23 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 23/29 Transformations affect all child nodes Sub-trees can be reused, called group nodes – instances of a group can have different transformations applied to them (e.g. group3 is used twice– once under t1 and once under t4) – must be defined before use object nodes (geometry) transformation nodes group nodes group3 obj3obj4 t5t6 t4 root t0 group1 t1t2 obj1group3 t3 group2 group3obj2 Transformations in Scene Graphs (3/3)

24 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 24/29 Transformation nodes contain at least a matrix that handles the transformation; – may also contain individual transformation parameters To determine final composite transformation matrix (CTM) for object node: – compose all parent transformations during prefix graph traversal – exact detail of how this is done varies from package to package, so be careful Composing Transformations in a Scene Graph (1/2)

25 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 25/29 Example: - for o1, CTM = m1 - for o2, CTM = m2* m3 - for o3, CTM = m2* m4* m5 - for a vertex v in o3, position in the world (root) coordinate system is: CTM v = (m2*m4*m5)v g: group nodes m: matrices of transform nodes o: object nodes m5 m1m2 m3 m4 o1 o2 o3 g1 g2 g3 Composing Transformations in a Scene Graph (2/2)

26 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 26/29 Exercises

27 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 27/29 Create a transform matrix that takes points in the rectangle [x l, x h ] x [y l, y h ] to the rectangle [x l ’, x h ’], [y l ’, y h ’] (Shirley Figure 6.18) E1: Windowing transforms =

28 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 28/29 Create a transform matrix that takes a point in the (X,Y) coordinate system to the point in the (U, V) coordinate system; and vice versa (Shirley Figure 6.20) E2: Transformation between two coordinate systems

29 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 29/29 Take-home exercise E3: Rotation about arbitrary axis

30 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 30/29 (right-handed coordinate system) Rotation axis specification

31 C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 31/29 Rotation about arbitrary axis


Download ppt "C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6."

Similar presentations


Ads by Google