Download presentation
Presentation is loading. Please wait.
1
Vectors Jeff Chastine
2
ππππ‘πππ A mathematical structure that has more than one βpartβ (e.g. an array) 2D vectors might have x and y 3D vectors might have x, y and z 4D vectors might have x, y, z and w Vectors can represent a point in space Vectors commonly represent both: Direction Magnitude Jeff Chastine
3
ππππ‘πππ A vector is often denoted with an arrow above it (e.g. π’ ) Row representation [x, y, z] (multiple columns) 15 β4 3 Column vector has multiple rows Vectors will be used in lighting equations 15 β4 3 Jeff Chastine
4
Example You Man-Bear-Pig
How would I describe the 2D difference in location of a player and an enemy? You Man-Bear-Pig Jeff Chastine
5
Example How would I describe the 2D difference in location of a player and an enemy? (x2, y2) (x1, y1) Jeff Chastine
6
Example ππππ =[ π₯ 1 β π₯ 2 , π¦ 1 β π¦ 2 ] (x2, y2) (x1, y1)
How would I describe the 2D difference in location of a player and an enemy? (x2, y2) (x1, y1) ππππ =[ π₯ 1 β π₯ 2 , π¦ 1 β π¦ 2 ] β¦or ππππ=[βπ₯, βπ¦] Note: a very useful 2D function is atan2 (βy, βx) which gives you the angle!
7
Interpretation (x2, y2) (x1, y1) Magnitude (length)
ππππ has both magnitude and direction (x2, y2) (x1, y1) Magnitude (length) Jeff Chastine
8
Interpretation (x2, y2) (x1, y1) (βx, βy) Direction (0, 0)
ππππ has both magnitude and direction (x2, y2) (x1, y1) (βx, βy) (0, 0) Direction Jeff Chastine
9
Adding/Subtracting Vectors
Do this component-wise Therefore, the vectors must be the same size Adding example β3 = Subtraction works the same way + = Jeff Chastine
10
Multiplication? Multiplying by a scalar (a single number)
6 * = What about multiplication? This isnβt really defined, but we do have Dot product Cross product Jeff Chastine
11
Magnitude and Normalization of Vectors
Normalization is a fancy term for saying the vector should be of length 1 Magnitude is just its length and denoted π Example for mag = π₯ 2 + π¦ 2 + π§ 2 mag = = 35 =~ To normalize the vector, divide each component by its magnitude Example from above = Magnitude of =~1 Jeff Chastine
12
The Dot Product π Also called the inner or scalar product
Multiply component-wise, then sum together Denoted using the dot operator π’ β π£ Example β β2 = 1β8 + 2β1 + 4ββ2 =2.0 Why is this so cool? If normalized, itβs the cosine of the angle ΞΈ between the two vectors! Use acosβ‘(π) to βundoβ that Basis of almost all lighting calculations! π Jeff Chastine
13
DOT PROduct Example π£ π π’ Assume we have two vectors: π’ = 1 0 0
π’ = π£ = These vectors are already normalized We expect the angle to be 90Β° Dot product is: π’ β π£ = 1β0 + 0β1 + 0β0 =0 acos 0 =90Β° π£ π π’ Jeff Chastine
14
DOT PROduct Example 2 π π£ π’ Assume we have two vectors: π’ = 1 0 0
π’ = π£ = β We expect the angle to be 180Β° Dot product is: π’ β π£ = 1ββ1 + 0β0 + 0β0 =β1 acos β1 =180Β° π π£ π’ Jeff Chastine
15
DOT PROduct Example 3 π’ π£ Assume we have two vectors: π’ = 1 0 0
π’ = π£ = We expect the angle to be 0Β° Dot product is: π’ β π£ = 1β1 + 0β0 + 0β0 =1 acos 1 =0Β° π’ π£ Jeff Chastine
16
Projection π πΌ π Length of projection is:
Can also be used to calculate the projection of one vector onto another π πΌ π Length of projection is: Then, multiply by normalized π/ π π cos πΌ = πβπ π ππππ π€ π= πβπ π 2 π Jeff Chastine
17
CROSS PRODUCT π π π π ππ₯ ππ¦ ππ§ ππ₯ ππ¦ ππ§
Gives us a new vector that is perpendicular to the other two Denoted with the Γ operator Calculations: π Γ π =[ π π¦ π π§ β π π§ π π¦ π π§ π π₯ β π π₯ π π§ π π₯ π π¦ β π π¦ π π₯ ] Interesting: If π Γ π = π then π Γ π =β π The magnitude (length) of the new vector is the sine of the angle (if normalized) π π π ππ₯ ππ¦ ππ§ ππ₯ ππ¦ ππ§ Jeff Chastine
18
CROSS PRODUCT π π π π ππ₯ ππ¦ ππ§ ππ₯ ππ¦ ππ§
Gives us a new vector that is perpendicular to the other two Denoted with the Γ operator Calculations: π Γ π =[ π π¦ π π§ β π π§ π π¦ π π§ π π₯ β π π₯ π π§ π π₯ π π¦ β π π¦ π π₯ ] Interesting: If π Γ π = π then π Γ π =β π The magnitude (length) of the new vector is the sine of the angle (if normalized) π π π ππ₯ ππ¦ ππ§ ππ₯ ππ¦ ππ§ Jeff Chastine
19
CROSS PRODUCT π π π π ππ₯ ππ¦ ππ§ ππ₯ ππ¦ ππ§
Gives us a new vector that is perpendicular to the other two Denoted with the Γ operator Calculations: π Γ π =[ π π¦ π π§ β π π§ π π¦ π π§ π π₯ β π π₯ π π§ π π₯ π π¦ β π π¦ π π₯ ] Interesting: If π Γ π = π then π Γ π =β π The magnitude (length) of the new vector is the sine of the angle (if normalized) π π π ππ₯ ππ¦ ππ§ ππ₯ ππ¦ ππ§ Jeff Chastine
20
CROSS PRODUCT π π π π ππ₯ ππ¦ ππ§ ππ₯ ππ¦ ππ§
Gives us a new vector that is perpendicular to the other two Denoted with the Γ operator Calculations: π Γ π =[ π π¦ π π§ β π π§ π π¦ π π§ π π₯ β π π₯ π π§ π π₯ π π¦ β π π¦ π π₯ ] Interesting: If π Γ π = π then π Γ π =β π The magnitude (length) of the new vector is the sine of the angle (if normalized) π π π ππ₯ ππ¦ ππ§ ππ₯ ππ¦ ππ§ Jeff Chastine
21
Fun Questions How do we find the normal of a triangle?
How can we determine if a polygon is facing away from the camera? Jeff Chastine
22
Fun Questions P0 P1 P2 How do we find the normal of a triangle?
How can we determine if a polygon is facing away from the camera? P0 P1 P2 Jeff Chastine
23
Fun Questions P0 π’ π£ P1 P2 Make some vectorsβ¦
How do we find the normal of a triangle? How can we determine if a polygon is facing away from the camera? P0 π’ π£ P1 P2 Make some vectorsβ¦ Jeff Chastine
24
Fun Questions P0 π’ π£ P1 P2 Make some vectorsβ¦
How do we find the normal of a triangle? How can we determine if a polygon is facing away from the camera? P0 π’ π£ P1 P2 Make some vectorsβ¦ Jeff Chastine
25
Fun Questions π’ Γ π£ P0 π’ π£ P1 P2 Take the cross product
How do we find the normal of a triangle? How can we determine if a polygon is facing away from the camera? π’ Γ π£ P0 π’ π£ P1 P2 Take the cross product Jeff Chastine
26
Fun Questions π P0 P1 P2 How do we find the normal of a triangle?
How can we determine if a polygon is facing away from the camera? π P0 P1 P2 Jeff Chastine
27
Fun Questions π P0 P1 P2 How do we find the normal of a triangle?
How can we determine if a polygon is facing away from the camera? π P0 P1 P2 Jeff Chastine
28
Fun Questions π P0 camera P1 P2
How do we find the normal of a triangle? How can we determine if a polygon is facing away from the camera? π P0 camera P1 P2 Jeff Chastine
29
Fun Questions π P0 πππ camera P1 P2
How do we find the normal of a triangle? How can we determine if a polygon is facing away from the camera? π P0 πππ camera P1 P2 Jeff Chastine
30
Fun Questions πΌπ acos πβπππ <90Β°, π π‘ β² π π£ππ ππππ π P0 πππ camera
How do we find the normal of a triangle? How can we determine if a polygon is facing away from the camera? πΌπ acos πβπππ <90Β°, π π‘ β² π π£ππ ππππ π P0 πππ camera P1 P2 Jeff Chastine Assuming π and πππ are normalized
31
A final Note Can multiply a matrix and vector to: Rotate the vector
Translate the vector Scale the vector Etc.. This operation returns a new vector Jeff Chastine
32
The End Image of a triangle facing away from the camera Jeff Chastine
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.