Transforms COMP 575/770 Spring 2013
Transforming Geometry Given any set of points S Could be a 2D shape, a 3D object A transform is a function T that modifies all points in S: T S S T v v S Different transforms can move, rotate, resize, deform, etc.
Translation Simplest transformation: T v = v + v 0 Inverse transform: T 1 v = v v 0
Linear Transforms Suppose we want a transform like: x = ax + by y = cx + dy Can express as a matrix-vector multiplication: x y = a b c d x y Called linear because T αu + βv = αt u + βt v
Linear Transforms We write column vectors, so matrices multiply on the left: x y = a b c d x y Some people write row vectors, where matrices multiply on the right (and are transposed): x y = x y a c b d
Linear Transforms Many kinds of transforms are linear Uniform scaling Non-uniform scaling Rotation Reflection Shearing We just need to know the matrices
Outline Transforms Gallery of Transforms
Uniform Scaling Make an object bigger or smaller Matrix form: M scale = s 0 0 s x = sx y = sy 1 M scale = 1 s 0 0 1 s
Non-Uniform Scaling Stretch an object along different directions Matrix form: x = s x x y = s y y M scale = s x 0 1 0 s M scale = y 1 s x 0 0 1 s y
Rotation y y r x Θ r = xi + yj r = x u + y v u = cos θi + sin θj v = sin θi + cos θj x
Rotation Rotate an object, pivoting around the origin Matrix form: x = x cos θ y sin θ y = x sin θ + y cos θ M rotate = cos θ sin θ sin θ cos θ 1 M rotate = cos θ sin θ sin θ cos θ
Reflection Reflect an object across a coordinate axis Matrix form: M reflect = 1 0 0 1 x = x y = y M reflect 1 = 1 0 0 1
Shearing Stretch and deform an object in a particular way Matrix form: M shear = 1 a 0 1 x = x + ay y = y M shear 1 = 1 a 0 1
Outline Transforms Gallery of Transforms Composing Transforms
Composing Transforms Suppose we apply two successive transforms: p T p S T p = S T p Need to represent S T In the same way as S and T
Composing Translations Suppose we translate by u T then by u S : T p = p + u T S p = p + u S S T p = p + (u T + u S ) Equivalent to translation by u T + u S Commutative!
Composing Linear Transforms Suppose we apply M T followed by M S : T p = M T p S p = M S p S T p = M S M T p Equivalent to applying M S M T Not always commutative!
Composing Linear Transforms scale, then rotate rotate, then scale
Outline Transforms Gallery of Transforms Composing Transforms Affine Transforms
Homogeneous Coordinates How to compose linear transforms and translation? With a unified representation Our equations are of this form: x = ax + by + c y = dx + ey + f Matrix-vector form: x y 1 = a b c d e f 0 0 1 x y 1 Homogeneous coordinates (extra w coordinate)
Affine Transforms Transform in homogeneous coordinates which preserves w Last row of matrix is always 0 0 1 Properties: Straight lines remain straight lines Parallel lines remain parallel Length ratios preserved (midpoints remain midpoints)
Translation
Uniform Scaling
Non-Uniform Scaling
Rotation
Reflection
Shearing
Composing Affine Transforms Analogous to composing linear transforms M T followed by M S equivalent to M S M T Not commutative!
Composing Affine Transforms rotate, then translate translate, then rotate
Rigid-Body Transforms Special case of affine transform Contains only rotation and translation: R = Q u 0 1 Since inverse of orthonormal matrix is its transpose: R 1 = Qt Q t u 0 1
Composite Transforms Want to rotate about a specific point We know how to rotate about the origin And how to translate to the origin
Composite Transforms Want to scale along a specific axis, about a point We know how to scale along y at the origin And how to rotate about / translate to the origin
Transforming Points vs. Vectors Distinction between points and vectors Points are locations Vectors are differences between points Respond differently to transformation Vectors cannot be translated, points can v = p q T x = Mx + t T v = T p q = Mp + t Mq + t = M p q + t t = Mv
Transforming Points vs. Vectors Homogeneous coordinates handle this neatly Just set w = 0 for vectors: v = v x v y 0 Subtracting two points gives a vector: p x p y 1 q x q y 1 = p x q x p y q y 0
Outline Transforms Gallery of Transforms Composing Transforms Affine Transforms Coordinate Frames
Coordinate Frames Want to describe points in an arbitrary frame In terms of canonical coordinates r r Mapping from (r x, r y ) to r u, r v using a matrix Define coordinates as follows: r = p + r u u + r v v
Matrix Multiplication Two interpretations Dot products with each row: x y w = a x a y a w b x b y b w c x c y c w x y w = a r b r c r Weighted sum of columns: x y w = a x a y a w b x b y b w c x c y c w x y w = x a x b x c x + y a y b y c y + z a z b z c z
Coordinate Frames Definition of coordinate frames: r = p + r u u + r v v Frame-to-canonical matrix: u v p 0 0 1 Transforms from given frame to canonical frame Canonical-to-frame is just the inverse
Similarity Transform How to apply transform defined wrt arbitrary frame For example, scale by a factor of 2 along (1,2) Composition using frame-to-canonical matrix: T e = FT F F 1 T e is the transform wrt canonical frame T F is the transform wrt given frame F is the frame-to-canonical matrix This is a similarity transform
Outline Transforms Gallery of Transforms Composing Transforms Affine Transforms 3D Transforms
3D Affine Transforms Straightforward extension of the 2D case Results in 4 4 matrices Rotation is a little trickier though
Translation
Scaling
Rotation About z Axis
Rotation About x Axis
Rotation About y Axis
General Rotations A rotation in 2D is around a point A rotation in 3D is around an axis Many more 3D rotations than 2D 2D 3D
Specifying Rotations Need to specify and axis and an angle Convention: Positive θ is CCW when axis points at you Alternative: Euler angles Sequence of 3 rotations, about coordinate axes
Axis-Angle Rotations Essentially a similarity transform Canonical-to-frame transform: Translate axis to pass through origin Rotate about y to get axis into x-y plane Rotate about z to align axis with x axis
Axis-Angle Rotations Alternative: Construct a coordinate frame Let {p, u, v, w} be a coordinate frame with p lying on the axis u along the axis Apply a similarity transform T = FR x F 1
Creating Orthonormal Frames How to create an orthonormal frame {u, v, w} given 1 or 2 vectors? Multiple applications Axis-angle rotation Moving a camera around Surface shading and more
Creating Orthonormal Frames Given vector a and secondary vector b Need u to be parallel to a, and b to lie in uv plane u = a a w = u b u b v = w u
Creating Orthonormal Frames Given a single vector a Need u to be parallel to a Pick an arbitrary b, then use the same process Need to make sure b isn t accidentally parallel to a Rule of thumb: b = a, with smallest entry set to 1
Axis-Angle Rotations Putting it all together: 1. Given axis a, use rule of thumb to determine b 2. Using a and b, construct orthonormal frame {p, u, v, w} 3. Construct frame-to-canonical matrix from for {p, u, v, w} 4. Apply similarity transform Rotate along x axis in the {p, u, v, w} frame
Outline Transforms Gallery of Transforms Composing Transforms Affine Transforms 3D Transforms Transforms and Surface Normals
Transforming Normal Vectors Suppose we apply a transform T to a surface Will the normals transform correctly under T? i.e., will they remain perpendicular to the surface? T We need a (slightly) different transform, say X
Transforming Normal Vectors Normal is perpendicular to surface tangent t Should continue to be so, after transformation: So we use: t n = t t n = 0 Mt Xn = t t M t Xn = 0 X = Mt 1 Mt Xn = t t M t M t 1 n = t t n = 0
The End But W will return in The Perspective Projection Matrix