Docsity

Lecture 11: 2D Transformations I - Vectors and Vector Operations, Slides of Computer Graphics

Partial preview of the text

Download Lecture 11: 2D Transformations I - Vectors and Vector Operations and more Slides Computer Graphics in PDF only on Docsity!

Computer Graphics

Lecture 11

2D Transformations I

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 )

 This just defines length and

direction , but not position

Vector Projections

Projection of v onto the

x-axis

2D Magnitude and Direction

 The magnitude (length) of a vector:

|V| = sqrt( Vx^2 + Vy^2 )

  • Derived from the Pythagorean theorem

 The direction of a vector:

a = tan-1^ (Vy / Vx)

a is angular displacement from the x-axis

3D Magnitude and Direction

 3D magnitude is a simple extension of 2D |V| = sqrt( Vx^2 + Vy^2 + Vz^2 )

 3D direction is a bit harder than in 2D

  • Need 2 angles to fully describe direction - Latitude/longitude is a real-world example

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 Docsity.com

Vector Normalization

Vnorm = V / |V| = (1, 2, 3) / 3. = (1 / 3.74, 2 / 3.74, 3 / 3.74) = (.27, .53, .80) |Vnorm| = sqrt( .27^2 + .53^2 + .80^2 ) = sqrt( .9 ) =.  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.

Vector Subtraction

 Equation:

V 3 = V 1 - V 2 = (V1x-V2x, V1y-V2y, V1z-V2z)

 Visually:

Dot Product

 The dot product of 2 vectors is a scalar

V 1.^ V 2 = (V1x V2x) + (V1y V2y ) + (V1z V2z )

 Or, perhaps more importantly for graphics: V 1.^ V 2 = |V 1 | |V 2 | cos(q) where q is the angle between the 2 vectors and q is in the range 0  q  

 The Dot Product computation can be simplified when it is known that the vectors are unit vectors V 1.^ V 2 = cos(q) because |V 1 | and |V 2 | are both 1

  • Saves 6 squares, 4 additions, and 2 square roots

Cross Product

 The cross product of 2 vectors is a vector V 1 x^ V 2 = ( 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

 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)

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