Lecture Notes: Computer Graphics
Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale it and rotate it
Transformation Two complementary views Geometric trans: Object is transformed relative to a stationary coordinate system Coordinate trans: Object is held stationary while the coordinate system is transformed Ex: moving an automobile against a scenic background Move the auto and keep the background fixed (GT) Keep the car fixed and move the background (CT)
Basic 2D Geometric Transformations Four basic types Translation Scaling Rotation Shear (possible using a combination of rotation and scaling)
Translation xnew = xold + tx ynew = yold + ty Simply moves an object from one position to another xnew = xold + tx ynew = yold + ty Note: House shifts position relative to origin y x 1 2 3 4 5 6 7 8 9 10
Scaling xnew = Sx × xold ynew = Sy × yold Scalar multiplies all coordinates WATCH OUT: Objects grow and move! xnew = Sx × xold ynew = Sy × yold Note: House shifts position relative to origin y x 1 2 3 4 5 6 7 8 9 10
Rotation xnew = xold × cosθ – yold × sinθ Rotates all coordinates by a specified angle xnew = xold × cosθ – yold × sinθ ynew = xold × sinθ + yold × cosθ Points are always rotated about the origin y 6 5 4 3 2 1 x 1 2 3 4 5 6 7 8 9 10
Shear Along X-axis Along Y-axis
Basic 2D Geometric Transformations Translation Scale Rotation Shear
Transformation and Matrix Multiplication Recall how matrix multiplication takes place:
Matrix Representation Represent a 2D Transformation by a Matrix Apply the Transformation to a Point Transformation Matrix Point
Matrix Representation Transformations can be combined by matrix multiplication Transformation Matrix Matrices are a convenient and efficient way to represent a sequence of transformations
2×2 Matrices What types of transformations can be represented with a 2×2 matrix? 2D Identity 2D Scaling
2×2 Matrices What types of transformations can be represented with a 2×2 matrix? 2D Rotation 2D Shearing
2×2 Matrices 2D Mirror over Y axis What types of transformations can be represented with a 2×2 matrix? 2D Mirror over Y axis 2D Mirror over (0,0)
2×2 Matrices 2D Translation What types of transformations can be represented with a 2×2 matrix? 2D Translation NO!! Only linear 2D transformations can be Represented with 2x2 matrix
Homogeneous Coordinates A point (x, y) can be re-written in homogeneous coordinates as (xh, yh, h) The homogeneous parameter h is a non-zero value such that: We can then write any point (x, y) as (hx, hy, h) We can conveniently choose h = 1 so that (x, y) becomes (x, y, 1)
Homogeneous Coordinates Add a 3rd coordinate to every 2D point (x, y, w) represents a point at location (x/w, y/w) (x, y, 0) represents a point at infinity (0, 0, 0) is not allowed y 2 (2, 1, 1) or (4, 2, 2) or (6, 3, 3) 1 x 1 2 Convenient Coordinate System to Represent Many Useful Transformations
Why Homogeneous Coordinates? Mathematicians commonly use homogeneous coordinates as they allow scaling factors to be removed from equations We will see in a moment that all of the transformations we discussed previously can be represented as 3*3 matrices Using homogeneous coordinates allows us use matrix multiplication to calculate transformations – extremely efficient!
Homogeneous Translation The translation of a point by (dx, dy) can be written in matrix form as: Representing the point as a homogeneous column vector we perform the calculation as:
Homogenous Coordinates To make operations easier, 2-D points are written as homogenous coordinate column vectors Translation: Scaling:
Basic 2D Transformations Basic 2D transformations as 3x3 Matrices Translate Scale Rotate Shear
Combining Transformations A number of transformations can be combined into one matrix to make things easy Allowed by the fact that we use homogenous coordinates Imagine rotating a polygon around a point other than the origin Transform to centre point to origin Rotate around origin Transform back to centre point
Matrix Composition Transformations can be combined by matrix multiplication Efficiency with premultiplication Matrix multiplication is associative
Combining Transformations (cont…) 1 2 3 4
Combining Transformations (cont…) The three transformation matrices are combined as follows REMEMBER: Matrix multiplication is not commutative so order matters
Matrix Composition Rotate by around arbitrary point (a,b) Scale by sx, sy around arbitrary point (a,b) (a,b) (a,b)
Inverse Transformations Transformations can easily be reversed using inverse transformations
Basic 2D Coordinate Transformations Translation Scale Rotation Shear ??