Presentation is loading. Please wait.

Presentation is loading. Please wait.

Geometric Transformations

Similar presentations


Presentation on theme: "Geometric Transformations"— Presentation transcript:

1 Geometric Transformations
Lecture 7 Fri, Sep 7, 2007

2 Geometric Transformations
Isometries are geometric transformations that preserve distances and angles Translation Rotation Reflection Non-isometries Scaling Shear

3 Geometric Transformations
Which of these transformations are linear? Which are affine? Translation Rotation Reflection Scaling Shear

4 2D vs. 3D Transformations All of these transformations may be performed in 2 or 3 dimensions. When they are performed in 2 dimensions, typically the z-coordinate of the points is 0. They are handled the same way whether in 2 or 3 dimensions.

5 Translations A translation is a displacement in a particular direction. A translation is defined by specifying the displacements x, dy, and dz. x  = x + x y  = y + y z  = z + z

6 Translations

7 Translations x = 10, y = 2, z = 0

8 Translations in OpenGL
The function glTranslate*(x, y, z) performs a translation through the displacement x, y, z. To translate an object, this function should be called before the object is drawn.

9 Translation Example Draw a triangle translated by (4, 2, -3).
glTranslatef(4.0, 2.0, -3.0); glBegin(GL_TRIANGLES); glVertex3f(0.0, 0.0, 0.0); glVertex3f(1.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glEnd();

10 Translation Example Read Run

11 Rotations A rotation turns about a point (a, b) through an angle .
Generally we rotate about the origin. Using the z-axis as the axis of rotation, the equations are x  = x cos  – y sin  y  = x sin  + y cos  z  = z

12 Rotations

13 Rotations z-axis,  = 90

14 Rotations in OpenGL The function glRotate*(, a, b, c) will rotate about the line x = at, y = bt, z = ct through an angle , measured in degrees. Typically, we rotate about The x-axis (1.0, 0.0, 0.0), The y-axis (0.0, 1.0, 0.0), or The z-axis (0.0, 0.0, 1.0).

15 Rotation Example Draw a triangle rotated by 90 about the z-axis.
glRotatef(90.0, 0.0, 0.0, 1.0); glBegin(GL_TRIANGLES); glVertex3f(0.0, 0.0, 0.0); glVertex3f(1.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glEnd();

16 Direction of Rotation The direction of rotation is determined by the “right-hand rule.” If you point your thumb in the positive direction of the axis of rotation, then when you curl your fingers, they will curl in the positive direction of rotation. This rule works even if you are left-handed, as long as you use your right hand.

17 Rotation Example Read Run

18 Scaling A scaling is an expansion or contraction in the x, y, and z directions by scale factors sx, sy, and sz, and centered at a point (a, b, c). Generally we center the scaling at the origin. x  = sx x y  = sy y z  = sz z

19 Scaling 10 5 5 10 15 20

20 Scaling 10 5 5 10 15 20 sx = 4, sy = 2, sz = 1

21 Scalings in OpenGL The function glScale*(sx, sy, sz) will scale the drawing by factors sx, sy, and sz in the x-, y-, and z-directions. The center of the scaling is the origin. Never use a scale factor of 0.

22 Scaling Example Draw a triangle scaled by factors 4, 2, and 1.
glScalef(4.0, 2.0, 1.0); glBegin(GL_TRIANGLES); glVertex3f(0.0, 0.0, 0.0); glVertex3f(1.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glEnd();

23 Scaling Example Read Run

24 Reflections A reflection is a reversal of an object with respect to a line in 2 dimensions or a plane in 3 dimensions. Generally we reflect in a line or plane through the origin.

25 Reflections

26 Reflection in the x-Axis

27 Reflection in the y-Axis

28 Reflection in the Line y = -x

29 Reflections in OpenGL The function glScale*(sx, sy, sz) will perform a reflection if one of the scale factors is negative. For example, to reflect in the y-axis, use glScalef(1.0, -1.0, 1.0);

30 Reflection Example Reflect a triangle in the y-axis.
glScalef(1.0, -1.0, 1.0); glBegin(GL_TRIANGLES); glVertex3f(0.0, 0.0, 0.0); glVertex3f(1.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glEnd();

31 Reflection Example Read Run

32 Reflections If we reflect in two axes at once (or in sequence), that amounts to a rotation of 180 in the axis perpendicular to those two axes. For example, glScalef(-1.0, -1.0, 1.0); is equivalent to glRotatef(180.0, 0.0, 0.0, 1.0);

33 Reflections To accomplish a reflection in an arbitrary line L: ax + by = 0 through the origin, First, reflect in the x-axis (y = 0). Then rotate through twice the angle between the line L and the x-axis.

34 Reflections To accomplish a reflection in an arbitrary plane P: ax + by + cz = 0 through the origin, First, reflect in the xy-plane (z = 0). Then rotate through twice the angle between the plane P and the xy-plane and about the line of intersection between the plane P and the xy-plane.


Download ppt "Geometric Transformations"

Similar presentations


Ads by Google