180 likes | 777 Views
2D Transformations, Homogeneous Coordinates, Change in Coordinates. Soon Tee Teoh CS 116A. Composite Transformations. What if we want to translate, then rotate about y axis, then translate again, then rotate about x axis …?
E N D
2D Transformations, Homogeneous Coordinates, Change in Coordinates Soon Tee Teoh CS 116A
Composite Transformations • What if we want to translate, then rotate about y axis, then translate again, then rotate about x axis …? • It would be tedious to perform repeated transformation for every vertex. • Need a better way to represent composite transformation.
Matrix representation of transformation • We saw last time: Scaling Rotation cos q - sin q sin q cos q sx 0 0 sy R = S =
Composite Transformations • Simply multiply single transformation matrices P’ = TP P’ = T2T1P Let Tc = T2T1 Then, P’ = TcP Matrix identities: A(BC) = (AB)C, but AB not necessarily equal to BA. If you want to perform transformation T1 on P first, and then perform T2, you have to put T1 on the right hand side, as shown above.
Homogeneous Coordinates • What is the translation matrix? • Translation adds rather than multiplies! • Therefore, to accommodate translation, we need: P’ = M1P + M2 where M1 takes care of rotation and scaling, while M2 takes care of translation. This is undesirable!
Homogeneous Coordinates • Solution: Homogeneous coordinates • Represent coordinates as (x,y,h) • Actual coordinates drawn will be (x/h,y/h)
Homogeneous Coordinates • The transformation matrices become 3x3 matrices, and we have a translation matrix! x’ y’ 1 1 0 tx 0 1 ty 0 0 1 x y 1 = New point Transformation Original point Exercise: Try composite translation.
Homogeneous Coordinates • Rotation and Scaling Matrices cos q - sin q 0 sin q cos q 0 0 0 1 sx 0 0 0 sy 0 0 0 1 R = S = Exercise: What is the transformation matrix of rotation by t around pivot point (xp,yp)?
2D Transformation: Reflection • Reflection about the x axis: Just flip the y coordinate • Reflection about the y axis: Just flip the x coordinate • Reflection about the origin, flip both coordinates Reflection about y axis Reflection about origin Reflection about x axis 1 1 1 1’ 2 3 2 3 2 3 3’ 2’ 3’ 2’ 2’ 3’ 1’ 1’ 1 0 0 0 -1 0 0 0 1 -1 0 0 0 1 0 0 0 1 -1 0 0 0 -1 0 0 0 1
2D Transformation: Shear • Distorts the shape of the object, as though the object has internal layers that slide. • Example: Shear relative to the x axis; that is, the x axis remains unchanged. • Specify shear factor s. • Then (x’,y’) = (x + sy, y) Example: Shear relative to x axis with shear factor 1: 3 2 1 1 2 3 4
Changing Coordinate System • P is described as (x,y) in the x-y coordinate system. We wish to describe P in the x’-y’ coordinate system. What is (x’,y’)? • First, translate by (x,y) by (-x0,-y0) • Then, rotate by - q y axis y y’ axis P x’ axis y’ x’ q y0 x axis x0 x
Changing Coordinate System y axis y y’ axis P x’ axis y’ x’ q x axis x y axis y axis/ y’ axis y’ axis P y’ P x’ axis y’ x’ q x’ x axis/x’ axis