Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Lecture 11 2D Transformations I Taqdees A. Siddiqi

Similar presentations


Presentation on theme: "Computer Graphics Lecture 11 2D Transformations I Taqdees A. Siddiqi"— Presentation transcript:

1 Computer Graphics Lecture 11 2D Transformations I Taqdees A. Siddiqi cs602@vu.edu.pk

2 Vectors  Another important mathematical concept used in graphics is the Vector  If P 1 = (x 1, y 1, z 1 ) is the starting point and P 2 = (x 2, y 2, z 2 ) is the ending point, then the vector V = (x 2 – x 1, y 2 – y 1, z 2 – z 1 )

3  and if P 2 = (x 2, y 2, z 2 ) is the starting point and P1 = (x 1, y 1, z 1 ) is the ending point, then the vector V = (x 1 – x 2, y 1 – y 2, z 1 – z 2 )

4  This just defines length and direction, but not position

5 Vector Projections  Projection of v onto the x-axis

6  Projection of v onto the xz plane

7 2D Magnitude and Direction  The magnitude (length) of a vector: |V| = sqrt( V x 2 + V y 2 ) Derived from the Pythagorean theorem  The direction of a vector:  = tan -1 (V y / V x )  is angular displacement from the x-axis

8 3D Magnitude and Direction  3D magnitude is a simple extension of 2D |V| = sqrt( V x 2 + V y 2 + V z 2 )  3D direction is a bit harder than in 2D – Need 2 angles to fully describe direction Latitude/longitude is a real-world example

9 – Direction Cosines are often used: , , and  are the positive angles that the vector makes with each of the positive coordinate axes x, y, and z, respectively cos  = V x / |V| cos  = V y / |V| cos  = V z / |V|

10 Vector Normalization  “Normalizing” a vector means shrinking or stretching it so its magnitude is 1 – creating unit vectors – Note that this does not change the direction  Normalize by dividing by its magnitude; V = (1, 2, 3) |V| = sqrt( 1 2 + 2 2 + 3 2 ) = sqrt(14) = 3.74

11 Vector Normalization V norm = V / |V| = (1, 2, 3) / 3.74 = (1 / 3.74, 2 / 3.74, 3 / 3.74) = (.27,.53,.80) |V norm | = sqrt(.27 2 +.53 2 +.80 2 ) = sqrt(.9 ) =.95  Note that the last calculation doesn’t come out to exactly 1. This is because of the error introduced by using only 2 decimal places in the calculations above.

12 Vector Addition  Equation: V 3 = V 1 + V 2 = (V 1x +V 2x, V 1y +V 2y, V 1z +V 2z )  Visually:

13 Vector Subtraction  Equation: V 3 = V 1 - V 2 = (V 1x -V 2x, V 1y -V 2y, V 1z -V 2z )  Visually:

14 Dot Product  The dot product of 2 vectors is a scalar V 1. V 2 = (V 1x V 2x ) + (V 1y V 2y ) + (V 1z V 2z )  Or, perhaps more importantly for graphics: V 1. V 2 = |V 1 | |V 2 | cos(  ) where  is the angle between the 2 vectors and  is in the range 0    

15  Why is dot product important for graphics? – It is zero iff the 2 vectors are perpendicular cos(90) = 0

16  The Dot Product computation can be simplified when it is known that the vectors are unit vectors V 1. V 2 = cos(  ) because |V 1 | and |V 2 | are both 1 – Saves 6 squares, 4 additions, and 2 square roots

17 Cross Product  The cross product of 2 vectors is a vector V 1 x V 2 = ( V 1y V 2z - V 1z V 2y, V 1z V 2x - V 1x V 2z, V 1x V 2y - V 1y V 2x ) – Note that if you are into linear algebra there is also a way to do the cross product calculation using matrices and determinants

18  Again, just as with the dot product, there is a more graphical definition: V 1 x V 2 = u |V 1 | |V 2 | sin(  ) where  is the angle between the 2 vectors and  is in the range 0     and u is the unit vector that is perpendicular to both vectors – Why u? |V 1 | |V 2 | sin(  ) produces a scalar and the result needs to be a vector

19  The direction of u is determined by the right hand rule – The perpendicular definition leaves an ambiguity in terms of the direction of u  Note that you can’t take the cross product of 2 vectors that are parallel to each other – sin(0) = sin(180) = 0  produces the vector (0, 0, 0)

20 Forming Coordinate Systems  Cross products are great for forming coordinate system frames (3 vectors that are perpendicular to each other) from 2 random vectors – Cross V 1 and V 2 to form V 3 – V 3 is now perpendicular to both V 1 and V 2 – Cross V 2 and V 3 to form V 4 – V 4 is now perpendicular to both V 2 and V 3 – Then V 2, V 4, and V 3 form your new frame

21  V 1 and V 2 are in the new xy plane

22 Basic Transformations  Translation  Rotation  Scaling

23  Translation – Straight line movement  Rotation – Circular movement w.r.t pivot  Scaling – Change of size

24 Translation tx = 2 ty = 3 Y X 0 1 1 2 2 3 4 5 6 7 8 9 10 3 4 5 6

25  Translation Distances t x, t y  For point P(x,y) after translation we have P′(x′,y′)  x′ = x + t x, y′ = y + t y  (t x, t y ) is Translation vector

26 Now x′ = x + t x, y′ = y + t y can be expressed as a single matrix equation: P′ = P + T Where P =P′ = T =

27  Rigid Body Transformation  Objects are moved without deformation  Every point on the object is translated by the same amount  Typically all the endpoints are translated and object is redrawn using new endpoint positions

28 Rotation Y X 0 1 1 2 2 3 4 5 6 7 8 9 10 3 4 5 6

29  Repositions an object along a circular path in xy-plane  Rotation Angle θ  Rotation Point (x r, y r )  θ is +ve  counterclockwise rotation  θ is -ve  clockwise rotation  θ is zero  ?

30  For simplicity, consider the pivot at origin and rotate point P (x,y) where x = r cosФ and y = r sinФ  If rotated by θ then:  x′ = r cos(Ф + θ) = r cosФ cosθ – r sinФ sinθ and  y′ = r sin(Ф + θ) = r cosФ sinθ + r sinФ cosθ

31  Replacing r cosФ with x and r sinФ with y, we have:  x′ = x cosθ – y sinθ and  y′ = x sinθ + y cosθ

32  Column vector representation: P′ = R. P  Where

33  For Row vector representation of P and P′, in order to get the same results:  Which is actually transpose of original R, therefore: P′ T = (R. P) T = P T. R T

34  When rotating about (x r,y r )  x’ = x r + (x - x r ) cosθ – (y - y r ) sinθ  y’ = y r + (x - x r ) sinθ – (y - y r ) cosθ  A better way of expressing these as matrix operations would be discussed later

35  Rigid Body Transformation  Objects are rotated without deformation  Every point on the object is rotated by the same angle  Typically all the endpoints are rotated and object is redrawn using new endpoint positions

36 Scaling Y X 0 1 1 2 2 3 4 5 6 7 8 9 10 3 4 5 6

37 Scaling  Scaling alters the size of an object  Scaling factors S x and S y are used  For polygons, coordinates of each vertex may be multiplied by S x & S y to produce the transformed coordinates: x′ = x.S x y′ = y.S y

38 In matrix form it can be expressed as : P′ = S.P

39 Scaling factor > 1 Scaling factor < 1 Scaling factor = 1 Same valued scaling factors  uniform scaling in x and y Different valued scaling factors  differential scaling in x and y

40 When scaling w.r.t. origin, both the size and distance form origin get scaled. Size and distance fro origin: for Scaling factor 2 (double the size and double the distance from origin.) for Scaling factor 0.5 (reduce the size to 50% and also the distance from origin to 50%.

41 This can be controlled by scaling w.r.t. a fixed point (x f,y f ) x’ = x f + (x - x f )S x y’ = y f + (y - y f )S y  These can be rewritten as: x’ = x. S x + x f (1 – S x ) y’ = y. S y + y f (1 – S y ) Where the terms x f (1 – S x ) and y f (1 – S y ) are constant for all points in the object

42 Computer Graphics Lecture 11 2D Transformations I Taqdees A. Siddiqi cs602@vu.edu.pk


Download ppt "Computer Graphics Lecture 11 2D Transformations I Taqdees A. Siddiqi"

Similar presentations


Ads by Google