350 likes | 566 Views
CS430 Computer Graphics. Transformations of Objects – 2D Part I. Topics. Matrix Prelim Introduction Fundamental Transformations Affine Transformations More Affine Transformations Inverse of Affine Transformations Composition of Affine Transformations. Matrix Prelim.
E N D
CS430 Computer Graphics Transformations of Objects – 2D Part I Chi-Cheng Lin, Winona State University
Topics • Matrix Prelim • Introduction • Fundamental Transformations • Affine Transformations • More Affine Transformations • Inverse of Affine Transformations • Composition of Affine Transformations
Matrix Prelim • Matrix: rectangle array of numbers • A: nm matrix n rows, m columns • A vector in nD-space an n1 matrix
Matrix Multiplication • A: nm matrix B: mp matrix C = A B : np matrix, where • Ai =i th row vector of A Bj =j th column vector of B cij = Ai • Bj • A B = B A ?? • A (B + C )= A B + A C ??
Identity Matrix • Identity matrix I
Determinant of Matrix • Determinant of a 22 matrix A: • Determinant of an nnmatrix A: where A1i = determinant of an (n-1)(n-1) matrix obtained by deleting the first row and i th column from A • Find the determinant of a 33 matrix! (p.824)
Transpose and Inverse of Matrix • Transpose of an nmmatrix A is an mnmatrix B • B = AT, i.e., bij = aji • Transpose of an n1 column vector is a 1n row vector • Inverse of an nnmatrix A is an nnmatrix B • B = A-1 • A B = B A = I
Introduction • Transformation: cornerstone of CG • Change the position, size, orientation of objects • We will focus on linear transformation • Like other graphics systems, transformation is also central to OpenGL
OpenGL Graphics Pipeline • OpenGL pipeline • Example • glBegin(GL_LINES); glVertex3f(…) // send P1 through the pipeline glVertex3f(…) // send P2 through the pipeline glVertex3f(…) // send P3 through the pipeline glEnd(); P1, P2, … Q1, Q2, … Process & display CT Q2 P2 Q1 P1
Transforming Points and Objects • Transformation alters each point P in space into a new point Q by means of formula or algorithm • P is mapped to Q • Q is the image of P under the mapping T • Fundamental transformations • Translate • Scale • Rotate
Fundamental Transformations - Translation • Translation • Change the position of an object • (Qx, Qy) = (Px + dx, Py + dy) or Q = P + T, where T = (dx, dy) y Q2 P2 Q1 dy x P1 dx
Translation Example • Example dx= 3 dy=-4
Sy=2 Sy=2 Sx=3 Sx=3 x x Fundamental Transformations - Scaling • Scaling • Change the size of an object • (Qx, Qy) = (Sx Px, SyPy) or or • Actually it is scaling about the origin X y
Scaling Example • Example Sx=1/2 Sy=1/4
Fundamental Transformations - Rotation • Rotation • Change the orientation of an object • (Qx, Qy) = (Pxcos -Pysin, Pxsin+ Pycos) or or • Derivation of rotation mapping? y Q r r P x
Fundamental Transformation -Rotation • Rotation (cont’d) • Rotation is performed about the origin y x
Rotation Example • Example = 45o
Affine Transformations • Questions • How do we scale/rotate about any point? • How do we combine transformations? • Problem of composing transformations • Translation: Q = T + P addition • Scaling: Q = SP multiplication • Rotation: Q = RP multiplication • Solution: homogeneous coordinates • Represent a 2D point (x, y) as (x, y, 1) • A vector (a, b) = (a, b, 0)
Affine Transformations • Coordinates of point Q are linear combinations of those of point P: • Translation, scaling, and rotation are affine transformations (so are their combinations)
Affine Transformations • Translation, scaling, and rotation are affine transformations • Succession of affine transformation is an affine transformation • Affine transformation from vector V to vector W : • The third row of the transformation matrix is always (0, 0, 1)
Fundamental Transformations Revisit • Translation • (Qx, Qy) = (Px + dx, Py + dy)
Fundamental Transformations Revisit • Scaling • (Qx, Qy) = (Sx Px, SyPy)
Fundamental Transformations Revisit • Rotation • (Qx, Qy) = (Pxcos -Pysin, Pxsin+ Pycos)
More Affine Transformations - Reflection • Reflection – special case of scaling • Sx< 0 reflection about the y-axis • Sy< 0 reflection about the x-axis y Sy=2 Sy=1 Sx=3 Sx=-0.5 x Sx=3 Sy=-2
More Affine Transformations - Reflection • Pure reflection • Each of the scale factors is either +1 or –1 • Examples • T(Px, Py) = (-Px, Py) flip horizontally about y-axis • T(Px, Py) = (Px, -Py) flip vertically about x-axis • T(Px, Py) = (-Px, -Py) ? • Uniform scaling • Sx= Sy = S, where |S| is magnification factor • Differential scaling • SxSy
More Affine Transformations - Shearing • ShearX • x-coordinate is translated by an amount that increases linearly with y • y-coordinate is unaffected • Can be used to make italic letters out of regular ones • (Qx, Qy) = (Px + hPy, Py)
More Affine Transformations - Shearing • ShearY • y-coordinate is translated by an amount that increases linearly with x • x-coordinate is unaffected • (Qx, Qy) = (Px, gPx + Py)
Inverse of Affine Transformations • If Q =MP, then P =M–1Q, where M–1 is the inverse of M (i.e., M M–1 = I ) where det M = m11m22 - m12m21 • Inverse of an affine transformation is an affine transformation!
Inverse of Affine Transformations • Translation: T -1(dx, dy) = T(-dx, -dy) • Scaling: S -1(Sx, Sy) = S(1/Sx, 1/Sy) • Rotation: R -1() = R(-) • ShearX: ShX-1(h) = ShX(-h) • ShearY: Shy-1(g) = Shy(-g) • Verify that those matrices are correct • If M = I, what transformation is it?
Composition of Affine Transformations • Composing (concatenating) transformations • Process of applying several transformations in succession to form one overall transformation • Composition of affine transformations is affine • If a sequence of transformations are represented by matrices M1, M2, …, Mn, then a point P is transformed to a point Q = (Mn((M2(M1P))) = (Mn M2M1)P
Composition of Affine Transformations • Example: Build a transformation matrix that • Rotates 45 degrees • Scales in x by 1.5 and in y by –2 • Translates by (3, 5) Find the transformed point of P = (1, 2) • Solution: Q = MP = (1.94, 0.758, 1)
Applications of Composition • Rotate about an arbitrary point (x, y) • Translate by (-x, -y) • Rotate about the origin through angle • Translate by (x, y) • Transformation matrix M = T(x, y)R()T(-x, -y) 3 2 1
Applications of Composition • Scale about an arbitrary point (x, y) • Translate by (-x, -y) • Scale in x by Sx and in y by Sy • Translate by (x, y) Transformation matrix M = T(x, y)S(Sx, Sy)T(-x, -y) = ?? • Window-to-viewport transformation is also a good example of composition of affine transformations (why?)
Applications of Composition • Reflection about an axis of reflection that makes an angel of with the x axis • Rotate by - • Reflect about x-axis (i.e., scale in x by 1 and in y by –1) • Rotate by
Applications of Composition • Reflection about an axis of reflection that makes an angel of with the x axis • Translation matrix M = R()S(1, -1)R(-) Let c = cos(-) and s = sin(-), Check it out!