Download presentation
Presentation is loading. Please wait.
Published byCaren McKinney Modified over 9 years ago
1
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Transformations of Objects – 2D Part I
2
2 Topics l Matrix Prelim l Introduction l Fundamental Transformations l Affine Transformations l More Affine Transformations l Inverse of Affine Transformations l Composition of Affine Transformations
3
3 Matrix Prelim l Matrix: rectangle array of numbers l A: n m matrix n rows, m columns l A vector in nD-space an n 1 matrix
4
4 Matrix Multiplication l A: n m matrix B: m p matrix C = A B : n p matrix, where l A i =i th row vector of A B j =j th column vector of B c ij = A i B j l A B = B A?? l A (B + C )= A B + A C??
5
5 Identity Matrix l Identity matrix I
6
6 Determinant of Matrix l Determinant of a 2 2 matrix A: l Determinant of an n n matrix A: where A 1i = determinant of an (n-1) (n-1) matrix obtained by deleting the first row and i th column from A l Find the determinant of a 3 3 matrix! (p.824)
7
7 Transpose and Inverse of Matrix l Transpose of an n m matrix A is an m n matrix B zB = A T, i.e., b ij = a ji zTranspose of an n 1 column vector is a 1 n row vector l Inverse of an n n matrix A is an n n matrix B zB = A -1 zA B = B A = I
8
8 Introduction l Transformation: cornerstone of CG l Change the position, size, orientation of objects l We will focus on linear transformation l Like other graphics systems, transformation is also central to OpenGL
9
9 OpenGL Graphics Pipeline l OpenGL pipeline l Example zglBegin(GL_LINES); glVertex3f(…) // send P1 through the pipeline glVertex3f(…) // send P2 through the pipeline glVertex3f(…) // send P3 through the pipeline glEnd(); CT Process & display P 1, P 2, …Q 1, Q 2, … P1P1 P2P2 Q1Q1 Q2Q2
10
10 Transforming Points and Objects l Transformation alters each point P in space into a new point Q by means of formula or algorithm zP is mapped to Q zQ is the image of P under the mapping T l Fundamental transformations zTranslate zScale zRotate
11
11 Fundamental Transformations - Translation l Translation zChange the position of an object z(Q x, Q y ) = (P x + d x, P y + d y ) or Q = P + T, where T = (d x, d y ) P2P2 P1P1 Q1Q1 dxdx dydy x y Q2Q2
12
12 Translation Example l Example d x = 3 d y =-4
13
13 Fundamental Transformations - Scaling l Scaling zChange the size of an object z(Q x, Q y ) = (S x P x, S y P y ) or zActually it is scaling about the origin S x =3 S y =2 x y S x =3 S y =2 x X
14
14 Scaling Example l Example S x =1/2 S y =1/4
15
15 Fundamental Transformations - Rotation l Rotation zChange the orientation of an object z(Q x, Q y ) = (P x cos -P y sin , P x sin + P y cos ) or l Derivation of rotation mapping? P Q x y r r
16
16 Fundamental Transformation - Rotation l Rotation (cont’d) zRotation is performed about the origin x y
17
17 Rotation Example l Example = 45 o
18
18 Affine Transformations l Questions zHow do we scale/rotate about any point? zHow do we combine transformations? l Problem of composing transformations zTranslation: Q = T + P addition zScaling: Q = S P multiplication zRotation: Q = R P multiplication l Solution: homogeneous coordinates zRepresent a 2D point (x, y) as (x, y, 1) zA vector (a, b) = (a, b, 0)
19
19 Affine Transformations l Coordinates of point Q are linear combinations of those of point P: l Translation, scaling, and rotation are affine transformations (so are their combinations)
20
20 Affine Transformations l Translation, scaling, and rotation are affine transformations l Succession of affine transformation is an affine transformation l Affine transformation from vector V to vector W : l The third row of the transformation matrix is always (0, 0, 1)
21
21 Fundamental Transformations Revisit l Translation z(Q x, Q y ) = (P x + d x, P y + d y )
22
22 Fundamental Transformations Revisit l Scaling z(Q x, Q y ) = (S x P x, S y P y )
23
23 Fundamental Transformations Revisit l Rotation z(Q x, Q y ) = (P x cos -P y sin , P x sin + P y cos )
24
24 More Affine Transformations - Reflection l Reflection – special case of scaling zS x < 0 reflection about the y-axis zS y < 0 reflection about the x-axis S x =3 S y =2 y S x =-0.5 S y =1 S x =3 S y =-2 x
25
25 More Affine Transformations - Reflection l Pure reflection zEach of the scale factors is either +1 or –1 zExamples yT(P x, P y ) = (-P x, P y ) flip horizontally about y-axis yT(P x, P y ) = (P x, -P y ) flip vertically about x-axis yT(P x, P y ) = (-P x, -P y ) ? l Uniform scaling zS x = S y = S, where |S| is magnification factor l Differential scaling zS x S y
26
26 More Affine Transformations - Shearing l ShearX zx-coordinate is translated by an amount that increases linearly with y zy-coordinate is unaffected zCan be used to make italic letters out of regular ones z(Q x, Q y ) = (P x + hP y, P y )
27
27 More Affine Transformations - Shearing l ShearY zy-coordinate is translated by an amount that increases linearly with x zx-coordinate is unaffected z(Q x, Q y ) = (P x, gP x + P y )
28
28 Inverse of Affine Transformations l If Q =MP, then P =M –1 Q, where M –1 is the inverse of M (i.e., M M –1 = I ) where det M = m 11 m 22 - m 12 m 21 l Inverse of an affine transformation is an affine transformation!
29
29 Inverse of Affine Transformations l Translation: T -1 (d x, d y ) = T(-d x, -d y ) l Scaling: S -1 (S x, S y ) = S(1/S x, 1/S y ) l Rotation: R -1 ( ) = R(- ) l ShearX: Sh X -1 (h) = Sh X (-h) l ShearY: Sh y -1 (g) = Sh y (-g) l Verify that those matrices are correct l If M = I, what transformation is it?
30
30 Composition of Affine Transformations l Composing (concatenating) transformations zProcess of applying several transformations in succession to form one overall transformation l Composition of affine transformations is affine l If a sequence of transformations are represented by matrices M 1, M 2, …, M n, then a point P is transformed to a point Q = (M n ( (M 2 (M 1 P))) = (M n M 2 M 1 )P
31
31 Composition of Affine Transformations l Example: Build a transformation matrix that zRotates 45 degrees zScales in x by 1.5 and in y by –2 zTranslates by (3, 5) Find the transformed point of P = (1, 2) zSolution: Q = M P = (1.94, 0.758, 1)
32
32 Applications of Composition l Rotate about an arbitrary point (x, y) zTranslate by (-x, -y) zRotate about the origin through angle zTranslate by (x, y) Transformation matrix M = T(x, y)R( )T(-x, -y) 1 2 3
33
33 Applications of Composition l Scale about an arbitrary point (x, y) zTranslate by (-x, -y) zScale in x by S x and in y by S y zTranslate by (x, y) Transformation matrix M = T(x, y)S(S x, S y )T(-x, -y) = ?? l Window-to-viewport transformation is also a good example of composition of affine transformations (why?)
34
34 Applications of Composition l Reflection about an axis of reflection that makes an angel of with the x axis zRotate by - zReflect about x-axis (i.e., scale in x by 1 and in y by –1) zRotate by
35
35 Applications of Composition l Reflection about an axis of reflection that makes an angel of with the x axis zTranslation matrix M = R( )S(1, -1)R(- ) Let c = cos(- ) and s = sin(- ), Check it out!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.