2D transformations and homogeneous coordinates Dr Nicolas Holzschuch Universit of Cape Ton e-mail: holzschu@cs.uct.ac.za
Map of the lecture Transformations in 2D: vector/matri notation eample: translation, scaling, rotation Homogeneous coordinates: consistant notation several other good points (later) Composition of transformations Transformations for the indo sstem
Transformations in 2D In the application model: a 2D description of an object (vertices) a transformation to appl Each verte is modified: f(,) g(,) Epress the modification
Translations Each verte is modified: +t +t Before After
Translations: vector notation Use vector for the notation: makes things simpler A point is a vector: A translation is merel a vector sum: P P + T
Scaling in 2D Coordinates multiplied b the scaling factor: s s Before After
Scaling in 2D, matri notation Scaling is a matri multiplication: P SP s 0 0 s
Rotating in 2D Ne coordinates depend on both and cosθ - sinθ sinθ + cosθ θ Before After
Rotating in 2D, matri notation A rotation is a matri multiplication: P RP cosθ sinθ sinθ cosθ
2D transformations, summar Vector-matri notation siplifies riting: translation is a vector sum rotation and scaling are matri-vector mult I ould like a consistent notation: that epresses all three identicall that epresses combination of these also identicall Ho to do this?
Homogeneous coordinates Introduced in mathematics: for projections and draings used in artiller, architecture used to be classified material (in the 1850s) Add a third coordinate, A 2D point is a 3 coordinates vector:
Homogeneous coordinates (2) To points are equal if and onl if: / / and / / 0: points at infinit useful for projections and curve draing Homogenize divide b. Homogenized points: 1
Translations ith homogeneous 1 0 t 0 1 t 0 0 1 + t + t +t +t
Scaling ith homogeneous s 0 0 0 s 0 0 0 1 s s s s
Rotation ith homogeneous cosθ sinθ 0 sinθ cosθ 0 0 0 1 cosθ sinθ sin θ + cosθ cosθ sinθ sinθ + cosθ
Composition of transformations To compose transformations, multipl the matrices: composition of a rotation and a translation: M RT all transformations can be epressed as matrices even transformations that are not translations, rotations and scaling
Rotation around a point Q Rotation about a point Q: translate Q to origin (T Q ), rotate about origin (R Θ ) translate back to Q (- T Q ). P (-T Q )R Θ T Q P
Beare! Matri multiplication is not commutative The order of the transformations is vital Rotation folloed b translation isver different from translation folloed b rotation careful ith the order of the matrices! Small commutativit: rotation commute ith rotation, translation ith translation
From World to Windo Inside the application: application model coordinates related to the model possibl floating point On the screen: piel coordinates integer restricted vieport: umin/uma, vmin/vma
From Model to Vieport ma min min ma
From Model to Vieport Model is (min,min)-(ma,ma) Vieport is (umin,vmin)-(uma,vma) Translate b (-min,-min) Scale b (, ) uma-umin ma-min vma-vmin ma-min Translate b (umin,vmin) M T ST
From Model to Vieport Piel Coordinates u Model Coordinates v M
Mouse position: inverse problem Mouse click: coordinates in piels We ant the equivalent in World Coord because the user has selected an object to dra something for interaction Ho can e convert from indo coordinates to model coordinates?
Mouse click: inverse problem Simpl inverse the matri: M 1 ( T ST ) 1 Model Coordinates u M 1 v Piels coordinates
2D transformations: conclusion Simple, consistent matri notation using homogeneous coordinates all transformations epressed as matrices Used b the indo sstem: for conversion from model to indo for conversion from indo to model Used b the application: for modelling transformations