Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transformations of Objects CVG lab. Introduction  Affine transformations : Affine transformations are a fundamental cornerstone of computer graphics.

Similar presentations


Presentation on theme: "Transformations of Objects CVG lab. Introduction  Affine transformations : Affine transformations are a fundamental cornerstone of computer graphics."— Presentation transcript:

1 Transformations of Objects CVG lab

2 Introduction  Affine transformations : Affine transformations are a fundamental cornerstone of computer graphics and are central to OpenGL as well as most other graphics systems.

3 Introduction to Transformations  The overall transformation is a combination of three elementary ones : scaling, rotation and translation.  Transformations are useful in a number of situations : 1. Composing a “scene” out of a number of objects. 2. Creating a complex object from a single “motif”. 3. A designer may to view an object from different vantage points and make a picture from each one. 4. In a computer animation, several objects must move to one another from frame to frame.

4 Introduction to Transformations

5  Where Are We Headed? Using Transformations with OpenGL A number of graphics platforms, including OpenGL, provide a “graphics pipeline,” or a sequence of operations that are applied to all points that are “sent through”. glBegin (GL_LINES) glVertex3f(...);//send P1 through the pipeline glVertex3f(...);//send P2 through the pipeline glVertex3f(...);//send P2 through the pipeline glEnd();

6 Introduction to Transformations  Object Transformations versus Coordinate Transformations -. There are two ways to view a transformation : as an object transformation or as a coordinate transformation.. An object transformation alters the coordinates of each point on the object to some rule, leaving the underlying coordinate system fixed.. A coordinate transformation defines a new coordinate system in terms of the old one and then represents all of the object’s points in this new system.

7 Introduction to Transformations 1.Transforming Points and Objects A transformation alters each point P in space (2D or 3D) into a new point Q by means of a specific formula or algorithm. P = (P x, P y, 1) Q = (Q x, Q y, 1) (Q x, Q y, 1) = T (P x, P y, 1) Q = T(P).

8 Introduction to Transformations 2.The Affine Transformations -. Affine transformations are the most common transformations used in computer graphics. -. Affine transformations have a simple form : The coordinates of Q are linear combinations of those of P. That is, (Q x, Q y, 1) = (m 11 P x +m 12 Py+m13, m11Px+m12Py+m13, 1) For an affine transformation, the third row of the matrix is always (0, 0, 1)

9 Introduction to Transformations 3. Geometric Effects of Elementary 2D Affine Transformations -. Affine transformations produce combinations of four elementary transformations : translation, scaling, rotation, and shear. a. Translation b. Scaling

10 Introduction to Transformations c. Rotation d. Shearing

11 Introduction to Transformations 4.The Inverse of an Affine Transformation Most affine transformations of interest are nonsingular, which means that the determinant of m Det M = m 11 m 22 – m 12 m 21 Q = MP by the inverse of M, denoted M -1 P = M -1 Q The inverse of M M-1 = 1/det M

12 Introduction to Transformations a. Scaling b. Rotation

13 Introduction to Transformations c. Shearing d. Translations

14 Introduction to Transformations 5.Composing Affine Transformations -. The process of applying several transformations in succession to form one overall transformation is called composing(or concatenating) the transformations. W = MP M = M 2 M 1

15 Introduction to Transformations 6.Example Composing 2D Transformations

16 Introduction to Transformations 7.Some Useful Properties of Affine Transformations a. Affine Transformations Preserve Affine Comvinations of Points W = a 1 P 1 + a 2 P 2 T(a 1 P 1 + a 2 P 2 ) = a 1 T(P 1 ) + a 2 T(P 2 ) MW = M (a 1 P 1 + a 2 P 2 ) = a 1 MP 1 + a 2 MP 2 b. Affine Transformations Preserve Lines and Planes L(t) = (1 – t)A + tB Q(t) = (1 - t)T(A) + tT(B) P(s, t) = sA + tB + (1 - s- t)C T(P(s, t)) = sT(A) + tT(B) + (1 – s – t)T(C)

17 Introduction to Transformations c. Parallelism of Lines and Planes is Preserved d. The Columns of the Matrix Reveal the Transformed Coordinate Frame M = = (m 1 | m 2 | m 3 ) ט = (0, 0, 1), I = (1, 0, 0), j = (0, 1, 0) m 1 = Mi. P = P x i + P y j + ט Q = P x m 1 + P y m 2 + m 3

18 Introduction to Transformations e. Relative Ratios Are Preserved f. Effect of Transformations on the Areas of Figures area after transformation / area before transformation = |det M|

19 Introduction to Transformations f. Every Affine Transformation Is Composed of Elementary Operations -. 2D affine Transformation : M = (translation)(shear)(scaling)(rotation) -. 3D affine transformation : M = (translation)(scaling)(rotation)(shear 1 )(shear 2 )

20 3D AFFINE TRANSFORMATIONS P = P x i + P y j +P Z K + ט P = (P X, P y, P z, 1) M = = M

21 3D AFFINE TRANSFORMATIONS 1.The Elementary 3D Transformations a. Translation b. Scaling

22 3D AFFINE TRANSFORMATIONS c. Shearing d. Rotations -. Elementary rotations about a coordinate axis Positive values of β cause a counterclockwise (CCW) rotation about an axis as one looks inward from a point on the positive axis toward the origin.

23 3D AFFINE TRANSFORMATIONS 90° rotation :. For a z-roll, the x-axis rotates to the y-axis.. For a x-roll, the y-axis rotates to the x-axis.. For a y-roll, the z-axis rotates to the x-axis.

24 3D AFFINE TRANSFORMATIONS. An x-roll R x (β) =. A y-roll R y (β) =

25 3D AFFINE TRANSFORMATIONS. An x-roll R z (β) =

26 3D AFFINE TRANSFORMATIONS 2. Composing 3D Affine Transformations M = M 2 M 1

27 3D AFFINE TRANSFORMATIONS 3. Combining Rotations M = R z (β 3 )R y (β 2 )R x (β 1 )  Rotations about an Arbitrary Axis EUSER’S THEOREM : Any rotation (or sequence of rotations) about a point is equivalent to a single rotation about some axis through that point. -. The Classic Way : We decompose the required rotation into a sequence of known steps:

28 3D AFFINE TRANSFORMATIONS 1. Perform two rotations so that u becomes aligned with the x-axis. 2. Do a z-roll through the angle β. 3. Undo the two alignment rotations to restore u to its original direction. R u (β) = R y (-θ)R z (Φ)R x (β)R z (- Φ)R y (θ)  The Constructive Way

29 3D AFFINE TRANSFORMATIONS R u (β) =

30 3D AFFINE TRANSFORMATIONS  Rotations about an Arbitrary Axis R u (β) = u x =( m 32 – m 23 )/ (2sin (β)) u y =( m 13 – m 31 )/ (2sin (β)) u z =( m 21 – m 12 )/ (2sin (β))

31 CHANGING COORDINATE SYSTEMS (P x, P y, 1) T = = M

32 CHANGING COORDINATE SYSTEMS  Successive Changes in a Coordinate Frame = M1 = M1M2

33 CHANGING COORDINATE SYSTEMS -. Transforming Points M = M 3 * M 2 * M 1. -. Transforming the Coordinate System M = M 1 * M 2 * M 3

34 USING AFFINE TRANSFORMATIONS IN A PROGRAM glBegin (GL_LINES) glVertex2d(V[0].x, V[0].y); glVertex2d(V[1].x, V[1].y); glVertex2d(V[2].x, V[2].y); ….. // the remaining points glEnd ( ); In either case, cvs.setWindow (...) ; cvs.setViewport (...) ;

35 USING AFFINE TRANSFORMATIONS IN A PROGRAM  The Hard Way Q = transform2D (M, P); cvs.moveTo (transform2D (M,V[0])) cvs.lineTo (transform2D (M,V[1])) cvs.lineTo (transform2D (M,V[2])) …

36 USING AFFINE TRANSFORMATIONS IN A PROGRAM  The Easy Way OpenGL maintains a so-called modelview matrix, and every vertex that is passed down the graphics pipeline is multiplied by this matrix.

37 USING AFFINE TRANSFORMATIONS IN A PROGRAM CT = CT*M. glScaled (sx, sy, 1.0) ; Postmultiply CT by a matrix that performs a scaling by sx in x and by sy in y ; put the result back into CT. No scaling in z is done.. glScaled (dx, dy, 1.0) ; Postmultiply CT by a matrix that performs a translation by dx in x and by dy in y ; put the result back into CT. No scaling in z is done.. glScaled (angle, 0, 1.0) ; Postmultiply CT by a matrix that performs a rotation through angle degrees about the z-axis. Put the result back into CT.

38 USING AFFINE TRANSFORMATIONS IN A PROGRAM

39 for (int count = 0; count<5; count ++) { starMotif ( ); cvs.rotate2D(72.0);//concatenate another rotation } void drawFlake() { for(int count = 0;count<6;count++) { flakeMotif(); cvs.scale2D(1.0, -1.0); flakeMotif(); cvs.scale2D(1.0, -1.0); cvs.rotate2D(60.0);}}

40 USING AFFINE TRANSFORMATIONS IN A PROGRAM 1.Saving the CT for Later Use

41 USING AFFINE TRANSFORMATIONS IN A PROGRAM

42 DRAWING 3D SCENES WITH OPENGL

43  Some OpenGL Tools for Modeling and Vewing -. Setting the Camera in OpenGL (for a Parallel Projection) glMatrixMode (GL_PROJEXTION); glLoadIdentity ( ); glOrtho (left, right, bottom, top, near, far);  Positioning and Aiming the Camera glMatixMode (GL_PROJECTION); glLoadIdentity ( ); glOrhto (-3.2, 3.2, -2.4, 2.4, 1, 50); glMatrixMode (GL_MODELVIEW); glLoadIdentity ( ); gluLookAt (4, 4, 4, 0, 1, 0, 0, 1, 0);


Download ppt "Transformations of Objects CVG lab. Introduction  Affine transformations : Affine transformations are a fundamental cornerstone of computer graphics."

Similar presentations


Ads by Google