Geometric Transformations 2 1 Basic TwoDimensional Geometric Transformations
Geometric Transformations 2 1
Basic Two-Dimensional Geometric Transformations • Basic geometric transformations: - Translation - Rotation - Scaling • Other useful transformations: - Reflection - Shear 2
Other Two-Dimensional Transformations Reflection • For a two-dimensional reflection, the image is generated relative to an axis of reflection by rotating the object 180 about the reflection axis. • Reflection about the line y=0 (the x axis): 3
Other Two-Dimensional Transformations Reflection • Reflection about the line x=0 (the y axis): • Reflection about any reflection point in the xy plane 4
Other Two-Dimensional Transformations Shear • A transformation that distorts the shape of an object • The transformed shape appears as if the object were composed of internal layers that had been caused to slide over each other 5
Other Two-Dimensional Transformations Shear • Shear transformation matrix in x direction : y (0, 1) y (2, 1) (1, 1) (3, 1) shx = 2 (0, 0) (1, 0) 6
Other Two-Dimensional Transformations Shear • Shear transformation matrix in Y direction : 7
Transformations between Two. Dimensional Coordinate Systems • A Cartesian x’y’ system specified with coordinate origin (xn, yn) and orientation angle in a Cartesian xy reference frame. y’ y x’ θ yn xn x 8
Transformations between Two. Dimensional Coordinate Systems • To transform object descriptions from xy coordinates to x’y’ coordinates, we set up a transformation that superimposes the axes onto the x’y’ axes. • This is done in two steps: – Translate so that the origin (xn, yn) of the x’y’ system is moved to the origin (0, 0) of the xy system. – Rotation the x’ axis onto the x axis with angel (-ϴ). 9
Transformations between Two. Dimensional Coordinate Systems 1 - Translation y’ y y P y ’ x’ y xn x’ y’ θ yn P x x θ x’ x 10
Transformations between Two. Dimensional Coordinate Systems 2 - Clockwise rotation y y ’ y y P ’ y y x’ P y’ x θ x’ x x x 11
Transformations between Two. Dimensional Coordinate Systems • After Applying the require transformations the process will be applied in reverse • This is done in two steps: – Rotation the x’ to its original place with angel (ϴ). – Translate so that the origin (xn, yn) of the x’y’ system is to its original place. 12
Geometric Transformation in Threedimensional Space • Extended from twodimensional methods by including considerations for the z coordinate • Accomplished in homogeneous coordinates using 4 x 4 matrix z axis y P z x x 13 axis
Geometric Transformation in Threedimensional Space Three-dimensional Translation (x, y, z) (x’, y’, z’) 14
Geometric Transformation in Threedimensional Space Three-dimensional Rotation • Rotation about z-axis: 15
Geometric Transformation in Threedimensional Space Three-dimensional Rotation • Rotation about x-axis: 16
Geometric Transformation in Threedimensional Space Three-dimensional Rotation • Rotation about y-axis: 17
Geometric Transformation in Threedimensional Space General Three-dimensional Rotations • Rotation around an axis parralel to one of the coordinate axes: - Move to the origin - Apply R( ) - Move back to original position • Transformation matrix: 18
Geometric Transformation in Threedimensional Space General Three-dimensional Rotations • Example: 19
Geometric Transformation in Threedimensional Space Three-dimensional Scaling (x, y, z) (x’, y’, z’) Scaled Position 20
Geometric Transformation in Opengl 21
Basic Transformations • gl. Translate{fd}(TYPE x, TYPE y, TYPE z); • Move an object by the given x, y, z values. • Ex. gl. Translatef(5, 7, 1) 22
Basic Transformations • gl. Rotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z); • Rotates an object in a counterclockwise direction about the vector (x, y, z). • Ex. gl. Rotatef(45. 0, 0. 0, 1. 0); 23
Basic Transformations • gl. Scale{fd}(TYPE x, TYPE y, TYPE z); • Multiply the x, y, z coordinate of every point in the object by the corresponding argument x, y, or z. • Ex. gl. Scalef(2. 0, -0. 5, 1. 0); 24
Order of Transformations • Call order is the reverse of the order the transforms are applied. • Different call orders result in different transforms! 25
Order of Transformations • Each transform multiplies the object by a matrix that does the corresponding transformation. • The transform closest to the object gets multiplied first. 26
Example: Modeling a Chair void Draw. Rect(float l, float h){ gl. Color 3 f(1. 0, 0. 5); gl. Begin(GL_QUADS); gl. Vertex 2 i(0, 0); gl. Vertex 2 i(0, l); gl. Vertex 2 i(h, 0); gl. End(); gl. Flush(); } void Draw. Chair() { Draw. Rect(10, 1); // draw leg gl. Push. Matrix(); gl. Translatef(9, 0, 0); Draw. Rect (10, 1); // draw leg gl. Pop. Matrix(); 27
Example: Modeling a Chair gl. Push. Matrix(); gl. Translatef(9, 0, 9); Draw. Rect (10, 1); // draw leg gl. Pop. Matrix(); gl. Push. Matrix(); gl. Translatef(0, 0, 9); Draw. Rect(10, 1); // draw leg gl. Pop. Matrix(); gl. Push. Matrix(); gl. Translatef(0, 9, 0); Draw. Rect(10, 10); // draw seat gl. Pop. Matrix(); } 28
Example: Put three chairs in the room void Draw. Room() { gl. Push. Matrix(); Draw. Chair(); gl. Pop. Matrix(); gl. Push. Matrix(); gl. Translatef(10, 0); Draw. Chair(); gl. Pop. Matrix(); z 20 10 } gl. Push. Matrix(); gl. Translatef(40, 0, 0); gl. Rotatef(45. 0, 0, 0, 1); Draw. Chair(); gl. Pop. Matrix(); 0 0 10 20 30 40 50 60 x 29
30
- Slides: 30