290 likes | 627 Views
2D Transformations. Dr. Aree Ali Mohammed Assistant Professor 2013-2014 3 rd Stage aree.ali@univsul.net. Objectives. Given a 2D object, transformation is to change the object’s Position (translation) Size (scaling) Orientation (rotation) Shapes (shear)
E N D
2D Transformations Dr. Aree Ali Mohammed Assistant Professor 2013-2014 3rd Stage aree.ali@univsul.net University of Sulaimani - School of Science - Computer Dept.
Objectives • Given a 2D object, transformation is to change the object’s • Position (translation) • Size (scaling) • Orientation (rotation) • Shapes (shear) • Apply a sequence of matrix multiplication to the object vertices University of Sulaimani - School of Science - Computer Dept.
What and Why Transformations • What is transformations? • The geometrical changes of an object from a current state to modified state. • Why the transformations is needed? • To manipulate the initially created object and to display the modified object without having to redraw it. University of Sulaimani - School of Science - Computer Dept.
Types of Transformations • Geometric Transformations • Translation • Rotation • scaling • Linear (preserves parallel lines) • Non-uniform scales, shears or skews • Projection (preserves lines) • Perspective projection • Parallel projection • Non-linear (lines become curves) • Twists, bends, warps, morphs,
Translation Translate over vector (tx, ty) x’=x+ tx, y’=y+ ty or y P+T T P x
Rotation y y P’ a P x x
Scaling Schale with factor sxand sy: x’= sx x, y’= sy y or y P’ P Q’ Q x x
Reflection I Reflext over x-axis: x’= x, y’= y or y x
Reflection II x-axis y-axis University of Sulaimani - School of Science - Computer Dept.
Reflection III line x=y Origin line x=-y University of Sulaimani - School of Science - Computer Dept.
Shear Shear the y-as: x’=x+fy, y’=y or y x
Homogeneous coordinates • Add an extra coordinate, W, to a point. • P(x,y,W). • Two sets of homogeneous coordinates represent the same point if they are a multiple of each other. • (2,5,3) and (4,10,6) represent the same point. • If W 0 , divide by it to get Cartesian coordinates of point (x/W,y/W,1). • If W=0, point is said to be at infinity.
Put it all together University of Sulaimani - School of Science - Computer Dept.
Example Non-commutative Composition Scale then Translate: p' = T ( S p ) = TS p (5,3) (2,2) Scale(2,2) Translate(3,1) (1,1) (3,1) (0,0) (0,0) Translate then Scale: p' = S ( T p ) = ST p (8,4) (4,2) Translate(3,1) Scale(2,2) (6,2) (1,1) (3,1) (0,0) Lecture 4
0 0 1 0 0 1 0 0 1 Example Non-commutative Composition Scale then Translate: p' = T ( S p ) = TS p 0 1 0 0 2 0 0 2 0 1 0 0 3 1 1 2 0 0 0 0 1 2 0 0 3 1 1 TS = = Translate then Scale: p' = S ( T p ) = ST p 0 2 0 1 0 2 2 0 0 0 1 0 3 1 2 0 6 2 ST = = Lecture 4
Example How are transforms combined? Rotate then Translate (3,sqrt(2)) (0,sqrt(2)) (1,1) Rotate 45 deg Translate(3,0) (0,0) (0,0) (3,0) Translate then Rotate (1,1) Translate(3,0) (3/sqrt(2),3/sqrt(2)) Rotate 45 deg (3,0) (0,0) (0,0) Caution: matrix multiplication is NOT commutative! Lecture 4
0 0 1 Example Non-commutative Composition Rotate then Translate: p' = T ( R p ) = TR p 0 1 0 -1 0 0 1 0 0 3 1 1 0 0 0 3 1 1 -1 0 0 -1 0 0 -1 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 TR = = Translate then Rotate: p' = R ( T p ) = RT p 0 1 -1 0 0 1 0 3 1 0 1 0 -1 3 1 -1 0 0 -1 0 0 -1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 1 0 0 1 RT = = Lecture 4
Rotation around a point I R 1) 2) 3)
Rotation around a point II R 1) 2) 3)
Rotation around point III R 1) 2) 3)
Rotation around point IV R 1) 2) 3)
Exercises Translate a polygon with a coordinates A(2,5), B(7,10) and C(10,2) by three units in x-direction and 4 units in y-direction. A point is rotated counterclockwise by an angle of 45. Find the rotation matrix and the resultant point. Scale the polygon in example (1) by two units in x- and two units in y-direction. Give a 3x3 homogenous coordinate transformation matrix for each of the following translations: Shift the image to the right 3-units Shift the image up 2-units Move the image down 2/3 unit and left 4-units
Homework I • I sat in the car, and realized the side mirror is 0.4m on my right and 0.3m in my front • I started my car and drove 5m forward, turned 30 degrees to right, moved 5m forward again, and turned 45 degrees to the right, and stopped • What is the position of the side mirror now, relative to where I was sitting in the beginning?
Homework II A. Find the transformation matrix that transforms the given square ABCD to half its size with center still remaining at the same position. The coordinates of the square are: A(1,1), B(3,1), C(3,3), D(1,3) and center at (2,2). Also find the resultant coordinates of square. B. Find a transformation of triangle A(1,0), B(0,1), C(1,1) by Rotating 45° about the origin and then translating one unit in x and y direction. Translating one unit in x and y directions and then rotating 45° about the origin.