VECTORS JEFF CHASTINE 1. A mathematical structure that has more than one “part” (e.g. an array)...
-
Upload
marilynn-emerald-gilbert -
Category
Documents
-
view
222 -
download
3
Transcript of VECTORS JEFF CHASTINE 1. A mathematical structure that has more than one “part” (e.g. an array)...
JEFF CHASTINE 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)
• Column vector has multiple rows
• Vectors will be used in lighting equations
[ 15−43 ]
JEFF CHASTINE 4
EXAMPLE• 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?
(x1, y1)
(x2, y2)
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 )]
JEFF CHASTINE 7
INTERPRETATION• has both magnitude and direction
(x1, y1)
(x2, y2)
Magnitude (length)
JEFF CHASTINE 8
INTERPRETATION• has both magnitude and direction
(x1, y1)
(x2, y2)
Direction
(∆x, ∆y)
(0, 0)
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
+ =
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 =
• mag =
• To normalize the vector, divide each component by its magnitude
• Example from above
• Magnitude of
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!
𝜃
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:
𝜃�⃗�
𝑣
JEFF CHASTINE 14
DOT PRODUCT EXAMPLE 2• Assume we have two vectors:
• We expect the angle to be 180°
• Dot product is:
𝜃
�⃗�𝑣
JEFF CHASTINE 15
DOT PRODUCT EXAMPLE 3• Assume we have two vectors:
• We expect the angle to be 0°
• Dot product is: �⃗⃗�𝑣
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
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• 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• 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…
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…
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
�⃗�×𝑣
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
�⃗�
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
�⃗�
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
�⃗�
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�⃗�𝑎𝑚
�⃗�
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
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
JEFF CHASTINE 32
THE END
Image of a triangle facing away from the camera