Affine Transformations ====================== I am somewhat reorganizing the presentation of this material as compared to what the slides do. I. Motivate transformations --------------------------- How do we represent an object? - a bunch of points - polygons with vertices We'll work in 2D for a while... Draw a square. How do we position this "canonical square" on the plane? We want: Rotation Translation Plus maybe: Scaling Other distortions? II. Basic Math - Linear xforms ------------------------------ How do we express a rotation - first, consider a point at 'old' = (1,0) on the unit circle... x = cos(theta) y = sin(theta) - then, consider a point at 'old' = (0,1) on the unit circle... x = -sin(theta) y = cos(theta) - for arbitrary point: xnew = cos(theta) * xold - sin(theta) * yold ynew = sin(theta) * xold + cos(theta) * yold Is there a more convenient way to represent this? point = [x] [y] [xnew] = [cos(theta) -sin(theta)][xold] [ynew] [sin(theta) cos(theta)] [yold] R = rotation matrix pnew = R * pold; What else can we do with a matrix like this? Identity: [1 0] [0 1] Uniform scaling: [a 0] [0 a] Non-uniform scaling: [a 0] [0 b] takes square into rectangle... Mirroring (negative scaling): [-1 0 [ 0 0] etc. Shear: [1 b] [0 1] x' = x + by y = y show how this affects a square. III. Basic Math -- Translations =============================== How do we translate a point? 1D: x' = x + shift_amount 2D: x' = x + shift_amount_x y' = y + shift_amount_y Combining all of this (rotation + translation): p' = R*p + T, where T = [shift_amount_x] [shift_amount_y] This is referred to as an *affine transformation*. This is sort of awkward - have to carry around both R and T. So use a trick: define p = [x] (homogeneous coordinates) [y] [1] Now, [x'] = [Rxx Ryx Tx][x] x' = Rxx * x + Ryx * y + Tx; [y'] [Rxy Ryy Ty][y] y' = Rxy * x + Ryy * y + Ty; [?] [0 0 1][1] 1 = 0*x + 0*y + 1*1; Show a translation... Rotation about arbitrary points ------------------------------- - Identify rotation point - Translate rotation point to origin - Perform rotation - Translate back Change of coordinate system =========================== Can also view rotations and translations as representing a *change of coordinate systems* rather than as *movement*. Show two pairs of coordinate axes... For rotation, project onto new axes as represented in old coordinate system: x' = [ux uy]xold [vx vy] THIS ONLY WORKS FOR ORTHOGONAL COORDINATE SYSTEMS For translation, add translation vector to take new axes to old origin. Change of coordinate systems for non-orthogonal coordordinate systems ===================================================================== --> --> P = a u + b v question: what is 'a', what is 'b'? For orthogonal coordinate systems, dot the equation above by u, and then by v. For non-orthogonal coordinate systems, must explicitly solve the system of equations. REST OF LECTURE =============== Take from Curless slides. * Points and vectors (w=1 vs. w=0) * Barycentric coordinates -- affine frame -- non-orthogonal axes * Cross products -- |a||b|sin(theta) = area of parallelogram right hand rule.