Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 7 Transformation 1 Geometric Transformations Transformation Basic 2D geometric transformation Homogeneous coordinates 2D transformations Translation.

Similar presentations


Presentation on theme: "Lecture 7 Transformation 1 Geometric Transformations Transformation Basic 2D geometric transformation Homogeneous coordinates 2D transformations Translation."— Presentation transcript:

1 Lecture 7 Transformation 1 Geometric Transformations Transformation Basic 2D geometric transformation Homogeneous coordinates 2D transformations Translation Scaling Rotation Composite transformations Other transformation: Shearing, Reflection 3D transformations Translation Rotation Scaling Composite transformations Other 3D transformation: Shearing, Reflection OpenGL Matrix stack

2 Lecture 7 Transformation 2 1. Basic 2D Transformation 2D Translation A translation moves a vertex to a new position by adding a displacement vector to it. Eg, The following translates the vertex to by adding (3,13) ( 7,7 )

3 Lecture 7 Transformation 3 2D Rotation x’ = r cos(  +  ) = r cos  cos   r sin  sin  = x cos  - y sin  y’ = r sin(  +  ) = r sin  cos  + r cos  sin  = x sin  + y cos    (x,y) (x’,y’) r r x=r cos  y=r sin 

4 Lecture 7 Transformation 4 2D Scaling x’ = x s x y’ = y s y (x’, y’) (x, y)

5 Lecture 7 Transformation 5 A linear transformation moves a vertex to a new position by multiplying it with a non-singular matrix. Eg, The following transforms the vertex (2, 3) to (3, 13) (3,13) ( 2,3 ) 2. Linear Transformations on vertices

6 Lecture 7 Transformation 6 Affine Transformations on vertices An affine transformation is a linear transformation followed by a translation. Its 2D general form is Affine transformations preserve lines. Many geometric movements of objects, eg, translations, rotations, and scalings are affine transformations.

7 Lecture 7 Transformation 7 3. Homogeneous coordinates A point in homogeneous coordinates (x, y, w), w ≠ 0, corresponds to the 2-D vertex (x/w, y/w) in Cartesian coordinates Conceive that the Cartesian coordinates axes lies on the plane of w = 1. The intersection of the plane and the line connecting the origin and (x, y, w) gives the corresponding Cartesian coordinates y w x w = 0 (x, y, w) w = 1 (x/w, y/w, 1) x y

8 Lecture 7 Transformation 8 E.g. both the points (6, 9, 3) and (4, 6, 2) in the homogeneous coordinates corresponds to (2, 3) in the Cartesian coordinates. Conversely, the point (2, 1) of the Cartesian corresponds to (2, 1, 1), (4, 2, 2) or (6, 3, 3) of the homogeneous y w x w = 0 (4, 2, 2) w = 1 (2, 1, 1) x y 6, 3, 3)

9 Lecture 7 Transformation 9 A 2-D vector (x, y) of Cartesian corresponds to (x, y, 0) in homogeneous coordinates and vice versa. Note that vectors and vertices have different representations in homogeneous coordinates. On the other hand, the transformation formulas for both vectors and vertices in homogeneous coordinates are identical. Such generalization enhances simplicity, and thus the reliability, of a graphics system Homogeneous coordinates of vectors

10 Lecture 7 Transformation D Transformation in Homogeneous form (1,1) (5,1) (1,3) (x,y) (3,2) (7,2) (3,4) (x’, y’) 2D Translation in Homogeneous form

11 Lecture 7 Transformation 11 2D Rotation in Homogeneous form

12 Lecture 7 Transformation 12 Eg, to rotate 45 o (  / 4 radian) sin  / 4 = cos  / 4 = (1,1) (5,1) (1,3) (x,y) (0,1.4) ( 2.8, 4.2 ) (-1.4, 2.8) (x’, y’)

13 Lecture 7 Transformation 13 (1,1) (5,1) (1,3) (x,y) (2,1/2) (10,1/2) (2,3/2) (x’, y’) 2D Translation in Homogeneous

14 Lecture 7 Transformation Composite a sequence of transformations 1.Translate the right-angle vertex to the origin (Tx = -1, Ty = -1) 2.Rotate 45 o (  / 4 radian) sin  / 4 = cos  / 4 = (1,1) (5,1) (1,3) (2.8,2.8) (-1.4,1.4) (0,0) (4,0) (0,2)

15 Lecture 7 Transformation 15

16 Lecture 7 Transformation Composite Transformation Implementation All practical transformations on vertices and vectors in homogeneous coordinates can be expressed as pure matrix multiplications. Such uniformity greatly enhance the run-time efficiency of a graphics system. Suppose that a set of 1 million vertices needs to go through three transformations representing by the matrices M 1, M 2, and M 3. A straightforward formula of the overall transformations for a vertex v is v´ = M 3 *M 2 *M 1 *v. As matrix multiplication is associative, we can compute M = M 3 *M 2 *M 1 in advance, then transform all 1 million vertices using the formula v´ = M*v.

17 Lecture 7 Transformation Other 2D Transformation Shearing Uneven scaling and shearing change the shape of an object An example of 2D shearing in x direction (To alter x-coordinates by an amount proportional to the y value.) y x (0,0) (0,1) (1,0) (1,1) y x (0,0) (2,1) (1,0) (3,1) x’ = x + 2y y’ = y

18 Lecture 7 Transformation 18 y x (0,0) (0,1) (1,0) (1,1) y x (0,0) (0,1) (1,2) (1,3) x’ = x y’ = 2x + y

19 Lecture 7 Transformation 19 Reflection about the x axis (x,y) (x,-y) Reflection about the y axis ? Reflection w.p.t the origin ? Reflection w.p.t the x = y

20 Lecture 7 Transformation 20 Reflection along a line Translate (0, -b) so that the line passes through the origin Rotate the line onto the x axis by -  o Reflect about the x axis Backward rotate backward translate (Be reminded that these operations must be specified in reverse order.) y =mx+b  b


Download ppt "Lecture 7 Transformation 1 Geometric Transformations Transformation Basic 2D geometric transformation Homogeneous coordinates 2D transformations Translation."

Similar presentations


Ads by Google