1 / 42

Fundamental Concepts of Computer Graphics: Vectors and Transformations

Explore the essential principles of computer graphics through vectors and transformations, including magnitude, direction, normalization, addition, subtraction, dot product, cross product, and basic transformations like translation, rotation, and scaling.

shorne
Download Presentation

Fundamental Concepts of Computer Graphics: Vectors and Transformations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer GraphicsLecture 112D Transformations ITaqdees A. Siddiqics602@vu.edu.pk

  2. Vectors • Another important mathematical concept used in graphics is the Vector • If P1 = (x1, y1, z1) is the starting point and P2 = (x2, y2, z2) is the ending point, then the vector V = (x2 – x1, y2 – y1, z2 – z1)

  3. and if P2 = (x2, y2, z2) is the starting point and P1 = (x1, y1, z1) is the ending point, then the vector V = (x1 – x2, y1 – y2, z1 – z2)

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

  5. y (5, 2) v x v' (5, 0) Vector Projections • Projection of v onto the x-axis

  6. y (5, 3, 2) v x v' (5, 0, 2) z • Projection of v onto the xz plane

  7. y |v| (5, 2) a x 2D Magnitude and Direction • The magnitude (length) of a vector: |V| = sqrt( Vx2 + Vy2 ) • Derived from the Pythagorean theorem • The direction of a vector: a = tan-1 (Vy / Vx) • a is angular displacementfrom the x-axis

  8. 3D Magnitude and Direction • 3D magnitude is a simple extension of 2D |V| = sqrt( Vx2 + Vy2 + Vz2 ) • 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: • a, b, and g are the positive angles that the vector makes with each of the positive coordinate axes x, y, and z, respectively cos a = Vx / |V| cos b = Vy / |V| cos g = Vz / |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( 12 + 22 + 32) = sqrt(14) = 3.74

  11. Vector Normalization Vnorm = V / |V| = (1, 2, 3) / 3.74 = (1 / 3.74, 2 / 3.74, 3 / 3.74) = (.27, .53, .80) |Vnorm| = sqrt( .272 + .532 + .802) = 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: V3 = V1 + V2 = (V1x+V2x , V1y+V2y , V1z+V2z) • Visually: y y V2 V3 V2 V1 V1 x x

  13. y y V3 V2 V2 V1 V1 x x Vector Subtraction • Equation: V3 = V1 - V2 = (V1x-V2x, V1y-V2y, V1z-V2z) • Visually:

  14. Dot Product • The dot product of 2 vectors is a scalar V1. V2 = (V1x V2x) + (V1y V2y )+ (V1z V2z ) • Or, perhaps more importantly for graphics: V1. V2 = |V1| |V2| cos(q) where q is the angle between the 2 vectors and q is in the range 0 q y V2 q V1 x

  15. y V2 V1 x • 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 V1. V2 = cos(q) because |V1| and |V2| are both 1 • Saves 6 squares, 4 additions, and 2 square roots

  17. Cross Product • The cross product of 2 vectors is a vector V1x V2 = ( V1y V2z - V1z V2y , V1z V2x - V1x V2z , V1x V2y - V1y V2x ) • 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: V1x V2 = u |V1| |V2| sin(q) where q is the angle between the 2 vectors and q is in the range 0 q and u is the unit vector that is perpendicular to both vectors • Why u? • |V1| |V2| sin(q) produces a scalar and the result needs to be a vector

  19. V2 u V1 • 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 V1 and V2 to form V3 • V3 is now perpendicular to both V1 and V2 • Cross V2 and V3 to form V4 • V4 is now perpendicular to both V2 and V3 • Then V2, V4, and V3 form your new frame

  21. V1 and V2 are in the new xy plane V2 V2 V1 V3 V1 V2 x V3 z V1 V1 V4 y

  22. Basic Transformations • Translation • Rotation • Scaling

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

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

  25. Translation Distances tx, ty • For point P(x,y) after translation we have P′(x′,y′) • x′ = x + tx , y′ = y + ty • (tx, ty) is Translation vector

  26. Now x′ = x + tx , y′ = y + ty 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 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 X

  29. Repositions an object along a circular path in xy-plane • Rotation Angle θ • Rotation Point (xr, yr) • θ 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 = PT . RT

  34. When rotating about (xr,yr) • x’ = xr + (x - xr) cosθ – (y - yr) sinθ • y’ = yr + (x - xr) sinθ – (y - yr) 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. 6 5 4 Y 3 2 1 0 1 2 3 4 5 6 7 8 9 10 X Scaling

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

  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 (xf,yf) • x’ = xf + (x - xf)Sx • y’ = yf + (y - yf)Sy • These can be rewritten as: • x’ = x. Sx + xf (1 – Sx) • y’ = y. Sy + yf (1 – Sy) • Where the terms xf (1 – Sx) and yf (1 – Sy) are constant for all points in the object

  42. Computer GraphicsLecture 112D Transformations ITaqdees A. Siddiqics602@vu.edu.pk

More Related