Presentation is loading. Please wait.

Presentation is loading. Please wait.

Vectors Jeff Chastine.

Similar presentations


Presentation on theme: "Vectors Jeff Chastine."β€” Presentation transcript:

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


Download ppt "Vectors Jeff Chastine."

Similar presentations


Ads by Google