vectors jeff chastine 1. a mathematical structure that has more than one “part” (e.g. an array)...
TRANSCRIPT
![Page 1: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/1.jpg)
JEFF CHASTINE 1
VECTORS
![Page 2: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/2.jpg)
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
![Page 3: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/3.jpg)
JEFF CHASTINE 3
�⃗�𝑒𝑐𝑡𝑜𝑟𝑠• A vector is often denoted with an arrow above it (e.g.)
• Row representation [x, y, z] (multiple columns)
• Column vector has multiple rows
• Vectors will be used in lighting equations
[ 15−43 ]
![Page 4: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/4.jpg)
JEFF CHASTINE 4
EXAMPLE• How would I describe the 2D difference in location of a player and an enemy?
You
Man-Bear-Pig
![Page 5: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/5.jpg)
JEFF CHASTINE 5
EXAMPLE• How would I describe the 2D difference in location of a player and an enemy?
(x1, y1)
(x2, y2)
![Page 6: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/6.jpg)
6
EXAMPLE• How would I describe the 2D difference in location of a player and an enemy?
(x1, y1)
(x2, y2)
Note: a very useful 2D function is atan2 (y, x) which gives you the angle!
…or
�⃗�𝑖𝑓𝑓 =[(𝑥1−𝑥2 ) , ( 𝑦1− 𝑦2 )]
![Page 7: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/7.jpg)
JEFF CHASTINE 7
INTERPRETATION• has both magnitude and direction
(x1, y1)
(x2, y2)
Magnitude (length)
![Page 8: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/8.jpg)
JEFF CHASTINE 8
INTERPRETATION• has both magnitude and direction
(x1, y1)
(x2, y2)
Direction
(∆x, ∆y)
(0, 0)
![Page 9: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/9.jpg)
JEFF CHASTINE 9
ADDING/SUBTRACTING VECTORS• Do this component-wise
• Therefore, the vectors must be the same size
• Adding example
• + =
• Subtraction works the same way
+ =
![Page 10: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/10.jpg)
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
![Page 11: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/11.jpg)
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 =
• mag =
• To normalize the vector, divide each component by its magnitude
• Example from above
• Magnitude of
![Page 12: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/12.jpg)
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
• Why is this so cool?
• If normalized, it’s the cosine of the angle θ between the two vectors!
• Use to “undo” that
• Basis of almost all lighting calculations!
𝜃
![Page 13: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/13.jpg)
JEFF CHASTINE 13
DOT PRODUCT EXAMPLE• Assume we have two vectors:
• These vectors are already normalized
• We expect the angle to be 90°
• Dot product is:
𝜃�⃗�
𝑣
![Page 14: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/14.jpg)
JEFF CHASTINE 14
DOT PRODUCT EXAMPLE 2• Assume we have two vectors:
• We expect the angle to be 180°
• Dot product is:
𝜃
�⃗�𝑣
![Page 15: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/15.jpg)
JEFF CHASTINE 15
DOT PRODUCT EXAMPLE 3• Assume we have two vectors:
• We expect the angle to be 0°
• Dot product is: �⃗⃗�𝑣
![Page 16: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/16.jpg)
JEFF CHASTINE 16
PROJECTION• Can also be used to calculate the projection of one vector onto another
‖𝑉‖cos (𝛼 )= 𝑉 ∙𝑊‖𝑉‖∙‖𝑊‖
𝑉
𝑊𝛼
𝑝𝑟𝑜𝑗𝑤𝑉=𝑉 ∙𝑊
‖𝑊‖2𝑊
Length of projection is: Then, multiply by normalized
![Page 17: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/17.jpg)
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)
𝜃
�⃗�
�⃗�
�⃗�
|𝑎𝑥 𝑎𝑦 𝑎𝑧𝑏𝑥 𝑏𝑦 𝑏 𝑧|
![Page 18: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/18.jpg)
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)
𝜃
�⃗�
�⃗�
�⃗�
|𝑎𝑥 𝑎𝑦 𝑎𝑧𝑏𝑥 𝑏𝑦 𝑏 𝑧|
![Page 19: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/19.jpg)
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)
𝜃
�⃗�
�⃗�
�⃗�
|𝑎𝑥 𝑎𝑦 𝑎𝑧𝑏𝑥 𝑏𝑦 𝑏 𝑧|
![Page 20: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/20.jpg)
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)
𝜃
�⃗�
�⃗�
�⃗�
|𝑎𝑥 𝑎𝑦 𝑎𝑧𝑏𝑥 𝑏𝑦 𝑏 𝑧|
![Page 21: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/21.jpg)
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?
![Page 22: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/22.jpg)
JEFF CHASTINE 22
FUN QUESTIONS• 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
![Page 23: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/23.jpg)
JEFF CHASTINE 23
FUN QUESTIONS• How do we find the normal of a triangle?
• How can we determine if a polygon is facing away from the camera?
P2
P0
P1
�⃗� 𝑣
Make some vectors…
![Page 24: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/24.jpg)
JEFF CHASTINE 24
FUN QUESTIONS• How do we find the normal of a triangle?
• How can we determine if a polygon is facing away from the camera?
P2
P0
P1
�⃗�𝑣
Make some vectors…
![Page 25: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/25.jpg)
JEFF CHASTINE 25
FUN QUESTIONS• How do we find the normal of a triangle?
• How can we determine if a polygon is facing away from the camera?
P2
P0
P1
�⃗�𝑣
Take the cross product
�⃗�×𝑣
![Page 26: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/26.jpg)
JEFF CHASTINE 26
FUN QUESTIONS• How do we find the normal of a triangle?
• How can we determine if a polygon is facing away from the camera?
P2
P0
P1
�⃗�
![Page 27: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/27.jpg)
JEFF CHASTINE 27
FUN QUESTIONS• How do we find the normal of a triangle?
• How can we determine if a polygon is facing away from the camera?
P2
P0
P1
�⃗�
![Page 28: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/28.jpg)
JEFF CHASTINE 28
FUN QUESTIONS• How do we find the normal of a triangle?
• How can we determine if a polygon is facing away from the camera?
P2
P0
P1camera
�⃗�
![Page 29: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/29.jpg)
JEFF CHASTINE 29
FUN QUESTIONS• How do we find the normal of a triangle?
• How can we determine if a polygon is facing away from the camera?
P2
P0
P1camera�⃗�𝑎𝑚
�⃗�
![Page 30: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/30.jpg)
JEFF CHASTINE 30
FUN QUESTIONS• How do we find the normal of a triangle?
• How can we determine if a polygon is facing away from the camera?
P2
P0
P1camera�⃗�𝑎𝑚
�⃗�
𝐼𝑓 acos (𝑁 ∙𝑐𝑎𝑚 )<90 ° ,𝑖 𝑡 ′ 𝑠𝑣𝑖𝑠𝑖𝑏𝑙𝑒
Assuming and are normalized
![Page 31: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/31.jpg)
JEFF CHASTINE 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
![Page 32: VECTORS JEFF CHASTINE 1. 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,](https://reader036.vdocument.in/reader036/viewer/2022062407/56649e175503460f94b03239/html5/thumbnails/32.jpg)
JEFF CHASTINE 32
THE END
Image of a triangle facing away from the camera