Review Transformations CIS 681 Transformations Modeling transformations build
Review: Transformations CIS 681
Transformations • Modeling transformations • build complex models by positioning (transforming) simple components relative to each other • Viewing transformations • placing virtual camera in the world • transformation from world coordinates to camera coordinates • Perspective projection of 3 D coordinates to 2 D • Animation • vary transformations over time to create motion CIS 681
Transformations - Modeling CIS 681
Transformations - Viewing OBJECT WORLD CIS 681 CAMERA
Modeling Transformations Transform objects/points Transform coordinate system CIS 681
Affine Transformations Transform P = (x, y, z) to Q = (x’, y’, z’). Affine transformation: x’ = m 11 x + m 12 y + m 13 z + m 14 y’ = m 21 x + m 22 y + m 23 z + m 24 z’ = m 31 x + m 32 y + m 33 z + m 34 CIS 681
Translation by (tx, ty, tz): x’ = x + tx; y’ = y + ty; z’ = z + tz. (tx, ty, tz) CIS 681
Scaling by (sx, sy, sz): x’ = sx x; y’ = sy y; z’ = sz z. CIS 681
Rotation counter-clockwise by angle around the z-axis: x’ = x cos( ) – y sin( ) ; y y’ = x sin( ) + y cos( ) ; z’ = z. r Proof: x = r cos( ); y = r sin( ); z r x x’ = r cos( + ) = r cos( ) – r sin( ) = x cos( ) – y sin( ); y’ = r sin( + ) = r cos( ) sin( ) + r sin( ) cos( ) = x sin( ) + y cos( ); CIS 681
Rotation around x-axis Rotation counter-clockwise by angle around the x-axis: x’ = x; y’ = y cos( ) – z sin( ) ; z’ = y sin( ) + z cos( ). z x CIS 681 y
Rotation around y-axis Rotation counter-clockwise by angle around the y-axis: y’ = y; z’ = z cos( ) – x sin( ) ; x x’ = z sin( ) + x cos( ). Or x’ = x cos( ) + z sin( ); y’ = y; y z’ = – x sin( ) + z cos( ). CIS 681 z
Matrix Multiplication Scaling by (sx, sy, sz): x’ = sx x; y’ = sy y; z’ = sz z. Rotation counter-clockwise by angle around the z-axis: x’ = x cos( ) – y sin( ) ; y’ = x sin( ) + y cos( ) ; z’ = z. Translation by (tx, ty, tz): x’ = x + tx; y’ = y + ty; z’ = z + tz. CIS 681
Homogeneous Coordinates Represent P by (x, y, z, 1) and Q by (x’, y’, z’, 1). (Homogeneous coordinates. ) Translation by (tx, ty, tz): x’ = x + tx; y’ = y + ty; z’ = z + tz. Scaling by (sx, sy, sz): x’ = sx x; y’ = sy y; z’ = sz z. CIS 681
Rotation Matrices Rotation counter-clockwise by angle around the z-axis: x’ = x cos( ) – y sin( ) ; y’ = x sin( ) + y cos( ) ; z’ = z. Rotation counter-clockwise by angle around the x-axis: x’ = x; y’ = y cos( ) – z sin( ) ; z’ = y sin( ) + z cos( ). Rotation counter-clockwise by angle around the y-axis: x’ = x cos( ) + z sin( ); y’ = y; z’ = – x sin( ) + z cos( ). CIS 681
Affine Transformation Matrix Affine transformation: x’ = m 11 x + m 12 y + m 13 z + m 14 y’ = m 21 x + m 22 y + m 23 z + m 24 z’ = m 31 x + m 32 y + m 33 z + m 34 Transformation Matrix: CIS 681
Shearing Shear along the x-axis: x’ = x + hy; y’ = y; z’ = z. y z CIS 681 x
Reflection across the x-axis: x’ = (-1) x; y’ = y; z’ = z. y z Reflection is a special case of scaling! CIS 681 x
Elementary Transformations • • Translation; Rotation; Scaling; Shear. CIS 681
Compose Transformations y • Scale by (2, 1, 1); • Translate by (20, 5, 0); • Rotate by 30° counter-clockwise around the z-axis; • Translate by (0, -50, 0). CIS 681 z x
Compose Transformation Matrices • Scale by (2, 1, 1); y • Translate by (20, 5, 0); • Rotate by 30° counter-clockwise around the z-axis; Translate x z • Translate by (0, -50, 0). Rotate CIS 681 Translate Scale
Compose Transformation Matrices • Scale by (2, 1, 1); y • Translate by (20, 5, 0); • Rotate by 30° counter-clockwise around the z-axis; z • Translate by (0, -50, 0). CIS 681 x
Order Matters! Transformations are not necessarily commutative! • Translate by (20, 0, 0). • Rotate by 30. • Translate by (20, 0, 0). y z y x z CIS 681 x
Order of Transformation Matrices Apply transformation matrices from right to left. • Translate by (20, 0, 0). • Rotate by 30. • Translate by (20, 0, 0). CIS 681
Which transformations commute? • • • Translation and translation? Scaling and scaling? Rotation and rotation? Translation and scaling? Translation and rotation? Scaling and rotation? CIS 681
Elementary Transformations Elementary transformations: • Translation; • Rotation; • Scaling; • Shear. Theorem: Every affine transformation can be decomposed into elementary operations. Euler’s Theorem: Every rotation around the origin can be decomposed into a rotation around the x-axis followed by a rotation around the yaxis followed by a rotation around the z-axis. (or a single rotation about an arbitrary axis). CIS 681
Vectors Vector V = (Vx, Vy, Vz). Homogeneous coordinates: (Vx, Vy, Vz, 0). Affine transformation: CIS 681
Vectors Rotation: Scaling: Translation: (Note: No change. ) CIS 681
Line through P 0 = (x, y, z, 1) in direction V = (Vx, Vy, Vz, 0): P(u) = P 0 T + u* VT {(x 0, y 0, z 0, 1) + u* (Vx, Vy, Vz, 0): u Reals}. Apply affine transformation matrix M to line P(u): M *P(u) { M (P 0 T + u VT) : u Reals} = { M P 0 T + u. M VT : u Reals} = { Q 0 + u V’ : u Reals}. Theorem: Affine transformations transform lines to lines. CIS 681
Affine Transformation of Lines y y z x z CIS 681 x
Affine Combinations R P b Q a b Q’ a R’ P’ CIS 681
Affine Combinations Affine combinations of P = (x, y, z, 1) and Q = (x’, y’, z’, 1): {R = a (x, y, z, 1) + b (x’, y’, z’, 1): a, b Reals and a + b = 1} Apply affine transformation matrix M to (a PT + b QT) gives: M (a PT + b QT) = M a PT + M b QT = a M P T + b M QT = a P’ + b Q’ = MR = R’ Theorem: Affine transformations preserve affine combinations. CIS 681
Affine Combinations Theorem: The affine combination of points P and Q is the line through P and Q. Affine combinations of P = (x, y, z, 1) and Q = (x’, y’, z’, 1): {a (x, y, z, 1) + b (x’, y’, z’, 1): a, b Reals and a + b = 1}. a = 1 - b so a (x, y, z, 1) + b (x’, y’, z’, 1) = (1 -b) (x, y, z, 1) + b (x’, y’, z’, 1) = (x, y, z, 1) + b ((x’, y’, z’, 1) – (x, y, z, 1)) = (x, y, z, 1) + b(x’-x, y’-y, z’-z, 0) = P + b*V Where V = Q-P CIS 681
Properties of Affine Transformations • • • Affine transformations map lines to lines; Affine transformations preserve affine combinations; Affine transformations preserve parallelism; Affine transformations change volume by | Det(M) |; Any affine transformation can be decomposed into elementary transformations. CIS 681
Coordinate Frame y j i k x z • Coordinate frame is given by origin and three mutually orthogonal unit vectors, i, j, k - defined in (x, y, z) space • Mutually orthogonal (dot products): i • j = ? ; i • k = ? ; j • k = ? . • Unit vectors (dot products): i • i = ? ; j • j = ? ; k • k = ? . CIS 681
Orientation Right handed coordinate system: Left handed coordinate system: y y z z x (Into page) x (Out of page) CIS 681
Orientation Right handed coordinate system: y j Left handed coordinate system: y i k j i k z x Cross product: i x j = ? How do you test whether (i, j, k) is left handed or right handed? CIS 681
Coordinate Transformations y j i k x z Given object data points defined in the (i, j, k, ) coordinate frame, Given the definition of (i, j, k, ) in into (x, y, z, 0) coordinates, How do you determine the coordinates of the object data points in the (x, y, z, 0) frame? CIS 681
Coordinate change (Translation) b y ( x, y, z) a (0, 0, 0) z c Change from (a, b, c, ) coordinates to (x, y, z, 0) coordinates: CIS 681 x
Coordinate change (Rotation) b x y ( x, y, z) (0, 0, 0) c z-axis rotation by a z Change from (a, b, c, ) coordinates to (x, y, z, 0) coordinates: CIS 681
Coordinate Transformations y j i k x z Given (I, j, k, p) defined in the (x, y, z, 0) coordinate frame, Transform points in (i, j, k, ) coordinate frame to (x, y, z, 0) coordinate frame. Affine transformation matrix: Maps (i, j, k, ) coordinates into (x, y, z, 0) coordinates! CIS 681
Composition of coordinate change y y’ y” M 1 z M 2 x’ ’ 0 z” x z’ x” M 1 changes from coordinate frame (x, y, z, ) to (x’, y’, z’, ’). M 2 changes from coordinate frame (x’, y’, z’, ’) to (x’’, y’’, z’’, ’’). Change from coordinate frame (x, y, z, ) to (x’’, y’’, z’’, 0): ? CIS 681
Object vs. coordinate transformations Translate and then rotate object: y y y x x z z x z Translate and then rotate coordinate frame: y z y’ y x z z’ y ’ x CIS 681 y’’ x’ z ’’ z’’ x
Object vs. coordinate transformations (2) Translate and then rotate object: y y y x x z z x z Rotate and then translate coordinate frame: y y’y z y’’ x z y z’ ’’ x’ ’ x CIS 681 x’’ z z’’ x
Order of transformations Let Mi be the transformation matrix for transformation Ti. Sequence of object (point) transformations, T 1, T 2, T 3. Transformation matrix = M 3 x M 2 x M 1. Sequence of coordinate system transformations, T 1, T 2, T 3. Transformation matrix = M 1 x M 2 x M 3. Note: Open. GL, Open. Inventor use coordinate system transformations. CIS 681
Transformations of normal vectors n n is a unit normal vector to plane . M is an affine transformation matrix. How is n transformed under: • translation? • rotation by ? • uniform scaling by s? • shearing or non-uniform scaling? CIS 681
Shear transformation n n’ n n is a unit normal vector to plane . M is the shear transformation matrix. M n. T = n! Want n’. CIS 681
Transformations of normal vectors Planar equation: a x + b y + c z + d = 0. Let N = (a, b, c, d). (Note: n = (a, b, c) for some real . ) Let P = (x, y, z, 1) be a point in plane . Planar equation: N • P = 0. M is an affine transformation matrix. (MT is M transpose. ) Let P’ = M PT. Find N’ such that N’ • P’ = 0. N • P = 0; N PT = 0; N (M-1 M) PT = 0; (N M-1) (M PT) = 0; (N M-1) P’T = 0; So N’ = NM-1 To put in column-vector form, (N’)T = (NM-1)T = (M-1)TNT So N’ = ((M-1)T NT)T and (M-1)T is the transformation matrix for N. Note: If M is a rotation matrix, (M-1)T = M. CIS 681 n P
- Slides: 47