Vectors, Points, Lines and Planes Jim Van Verth ([email protected]) Lars M. Bishop...
-
Upload
cristina-cupp -
Category
Documents
-
view
230 -
download
1
Transcript of Vectors, Points, Lines and Planes Jim Van Verth ([email protected]) Lars M. Bishop...
![Page 1: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/1.jpg)
Vectors, Points, Lines and Planes
Jim Van Verth ([email protected])
Lars M. Bishop ([email protected])
![Page 2: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/2.jpg)
Essential Math for Games
Geometric Representation
• Problem Represent geometric data in computer?
• Solution Vectors and points Can represent most abstract objects as
combinations of these E.g. lines, planes, polygons
![Page 3: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/3.jpg)
Essential Math for Games
What Is a Vector?
• Geometric object with two properties direction length (if length is 1, is unit vector)
• Graphically represented by
![Page 4: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/4.jpg)
Essential Math for Games
Scale
• Graphically change length of vector v by
![Page 5: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/5.jpg)
Essential Math for Games
Addition
• Graphically put tail of second vector at head of first draw new vector from tail of first to head of
secondb
a
a + b
![Page 6: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/6.jpg)
Essential Math for Games
Algebraic Vectors
• Algebraically, vectors are more than this
• Any entity that meets certain rules (lies in vector space) can be called ‘vector’
• Ex: Matrices, quaternions, fixed length polynomials
• Mostly mean geometric vectors, however
![Page 7: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/7.jpg)
Essential Math for Games
Vector Space
• Set of vectors related by +,·• Meet rules
v + w = w + v (commutative +) (v + w) + u = v + (w + u) (associative +) v + 0 = v (identity +) v + (-v) = 0 (inverse +) () v = (v) (associative ·) (+)v = v + v (distributive ·) (v + w) = v + w (distributive ·)
![Page 8: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/8.jpg)
Essential Math for Games
Number Spaces
• Cardinal – Positive numbers, no fractions• Integer – Pos., neg., zero, no fractions• Rational – Fractions (ratios of integers)• Irrational – Non-repeating decimals (,e)• Real – Rationals+irrationals• Complex – Real + multiple of -1
a+bi
![Page 9: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/9.jpg)
Essential Math for Games
Real Vector Spaces
• Usually only work in these• Rn is an n-dimensional system of real
numbers Represented as ordered list of real
numbers (a1,…,an)
• R3 is the 3D world, R2 is the 2D world
![Page 10: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/10.jpg)
Essential Math for Games
Linear Combination
• Combine set of n vectors using addition and scalar multiplication v = 1v1 + 2v2 + … + nvn
• Collection of all possible linear combinations for given v1… vn is called a span
• Linear combination of 2 perpendicular vectors span a plane
![Page 11: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/11.jpg)
Essential Math for Games
Linear Dependence
• A system of vectors v1, … ,vn is called linearly dependant if for at least one vi
vi = 1v1 +…+ i-1vi-1 + i+1vi+1 +…+ nvn
• Otherwise, linearly independent• Two linearly dependant vectors are said
to be collinear I.e. w = .v I.e. they point the “same” direction
![Page 12: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/12.jpg)
Essential Math for Games
Linear Dependence
• Example
• Center vector can be constructed from outer vectors
Vector Prerequisites
![Page 13: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/13.jpg)
Essential Math for Games
Vector Basis
• Ordered set of n lin. ind. vectors = { v1, v2, …, vn}
• Span n-dimensional space
• Represent any vector as linear combo v = 1v1 + 2v2 + … + nvn
• Or just components v = (1, 2, …, n)
![Page 14: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/14.jpg)
Essential Math for Games
Vector Representation
• 3D vector v represented by (x, y, z) Use standard basis { i, j, k } Unit length, perpendicular (orthonormal) v = xi + yj + zk
• Number of units in each axis direction
v1
v3
v2
![Page 15: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/15.jpg)
Essential Math for Games
Vector Operations
• Addition: +,-
• Scale: ·
• Length: ||v||
• Normalize:
![Page 16: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/16.jpg)
Essential Math for Games
Addition
• Add a to b
b
a
a + b
332211 b,ab,aba ba
![Page 17: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/17.jpg)
Essential Math for Games
Scalar Multiplication
• change length of vector v by )αααα 321 v,v,v (v
![Page 18: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/18.jpg)
Essential Math for Games
Length
• Length ||v|| gives length (or Euclidean norm) of v
if ||v|| is 1, v is called unit vector usually compare length squared
• Normalize v scaled by 1/||v|| gives unit vector
23
22
21 vvv v
![Page 19: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/19.jpg)
Essential Math for Games
Vector Operations
• Games tend to use most of the common vector operations Addition, Subtraction Scalar multiplication
• Two others are extremely common: Dot product Cross product
![Page 20: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/20.jpg)
Essential Math for Games
Dot product
• Also called inner product, scalar product
a
b
![Page 21: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/21.jpg)
Essential Math for Games
Dot Product: Uses
• a • a equals ||a||2
• can test for collinear vectors if a and b collinear & unit length, |a • b| ~ 1 Problems w/floating point, though
• can test angle/visibility a • b > 0 if angle < 90° a • b = 0 if angle = 90° (orthogonal) a • b < 0 if angle > 90°
![Page 22: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/22.jpg)
Essential Math for Games
Dot Product: Example
• Suppose have view vector v and vector t to object in scene (t = o - e)
• If v • t < 0, object behind us, don’t draw
v
to
e
![Page 23: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/23.jpg)
Essential Math for Games
Dot Product: Uses
• Projection of a onto b is
a
b
![Page 24: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/24.jpg)
Essential Math for Games
Dot Product: Uses
• Example: break a into components collinear and perpendicular to b
a
b
![Page 25: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/25.jpg)
Essential Math for Games
Cross Product
• Cross product: definition
returns vector perpendicular to a and b right hand rule length = area of parallelogram
a
bc
![Page 26: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/26.jpg)
Essential Math for Games
Cross Product: Uses
• gives a vector perpendicular to the other two!
• ||a b|| = ||a|| ||b|| sin()
• can test collinearity ||a b|| = 0 if a and b are collinear Better than dot – don’t have to be
normalized
![Page 27: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/27.jpg)
Essential Math for Games
Other Operations
• Several other vector operations used in games may be new to you: Scalar Triple Product Vector Triple Product
• These are often used directly or indirectly in game code, as we’ll see
![Page 28: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/28.jpg)
Essential Math for Games
Scalar Triple Product
• Dot product/cross product combo
• Volume of parallelpiped
• Test rotation direction Check sign
w
v
u
![Page 29: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/29.jpg)
Essential Math for Games
Triple Scalar Product: Example
• Current velocity v, desired direction d on xy plane
• Take
• If > 0, turn left, if < 0, turn right
v
dv d
d
v
v d
![Page 30: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/30.jpg)
Essential Math for Games
Vector Triple Product
• Two cross products
• Useful for building orthonormal basis Compute and normalize:
![Page 31: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/31.jpg)
Essential Math for Games
Points
• Points are positions in space — anchored to origin of coordinate system
• Vectors just direction and length — free-floating in space
• Can’t do all vector operations on points
• But generally use one class in library
![Page 32: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/32.jpg)
Essential Math for Games
• Two points related by a vector (Q - P) = v P + v = Q
Point-Vector Relations
vQ
P
![Page 33: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/33.jpg)
Essential Math for Games
• Vector, point related by origin (P - O) = v O + v = P
• Vector space, origin, relation between them make an affine space
Affine Space
v
P
O
e3
e2e1
![Page 34: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/34.jpg)
Essential Math for Games
Cartesian Frame
• Basis vectors {i, j, k}, origin (0,0,0)
• 3D point P represented by (px, py, pz)
• Number of units in each axis direction relative to origin
opx
pz
py
![Page 35: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/35.jpg)
Essential Math for Games
Affine Combination
• Like linear combination, but with points P = a1P1 + a2P2 + … + anPn
a1,…,an barycentric coord., add to 1
• Same as point + linear combination P = P1 + a2 (P2-P1) + … + an (Pn-P1)
• If vectors (P2-P1), …, (Pn-P1) are linearly independent, {P1, …, Pn} called a simplex (think of as affine basis)
![Page 36: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/36.jpg)
Essential Math for Games
Convex Combination
• Affine combination with a1,…,an between 0 and 1
• Spans smallest convex shape surrounding points – convex hull
• Example: triangle
![Page 37: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/37.jpg)
Essential Math for Games
Points, Vectors in Games
• Points used for models, position vertices of a triangle
• Vectors used for velocity, acceleration indicate difference between points, vectors
![Page 38: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/38.jpg)
Essential Math for Games
Parameterized Lines
• Can represent line with point and vector P + tv
• Can also represent an interpolation from P to Q P + t(Q-P) Also written as (1-t)P + tQ
P vQ
![Page 39: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/39.jpg)
Essential Math for Games
Planes
• 2 non-collinear vectors span a plane
• Cross product is normal n to plane
n
![Page 40: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/40.jpg)
Essential Math for Games
Planes
• Defined by normal n = (A, B, C) point on plane P0
• Plane equation Ax+By+Cz+D = 0 D=-(A·P0x + B·P0y + C·P0z)
![Page 41: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/41.jpg)
Essential Math for Games
Planes
• Can use plane equation to test locality of point
• If n is normalized, gives distance to plane
n Ax+By+Cz+D > 0
Ax+By+Cz+D = 0
Ax+By+Cz+D < 0
![Page 42: Vectors, Points, Lines and Planes Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)](https://reader035.fdocuments.us/reader035/viewer/2022062303/55199cfa55034643068b4a44/html5/thumbnails/42.jpg)
Essential Math for Games
References
• Anton, Howard and Chris Rorres, Elementary Linear Algebra, 7th Ed, Wiley & Sons, 1994.
• Axler, Sheldon, Linear Algebra Done Right, Springer Verlag, 1997.
• Blinn, Jim, Notation, Notation, Notation, Morgan Kaufmann, 2002.