210 likes | 394 Views
Mathematical Foundations. Useful math for graphics and games. Mathematical Topics. Lots of math used in graphics and games Various concepts in this course: aliasing coordinate systems homogeneous coordinates matrices quaternions vectors. Vectors.
E N D
Mathematical Foundations Useful math for graphics and games
Mathematical Topics • Lots of math used in graphics and games • Various concepts in this course: • aliasing • coordinate systems • homogeneous coordinates • matrices • quaternions • vectors
Vectors • quantity expressing magnitude and direction • often written with respect to a basis • e.g., basis vectors i, j, k • p = ai + bj + ck bj j ai i
Vector magnitude • length of vector == magnitude • p = ai + bj + ck • |p| = sqrt(a*a + b*b + c*c) • Normalized vector: magnitude is 1
Aside: Normal vector • Perpendicular to surface • Specified at vertices in usual geometric models
Vector Notation • “How do you know if something is a vector?” • In code – look at the type! • XNA: Vector2, Vector3, Vector4 • In math (or on slides) – may not have types
Vector Notation → • Has an arrow: x • in bold (sometimes) ax + y • very hard to see, I hate this notation • use domain knowledge • F=ma: which quantities are vectors?
Vector Notation • Often you want to extract components of a vector • If written explicitly, p = ai + bj + ck, can refer to pieces by symbol • If not… • Index like arrays: p[0] • Subscript to show what piece: px
Vector Notation • Special symbol for a unit vector (length 1): ^ • so if we have ŵ, by definition |ŵ| = 1 • Used sometimes in addition to arrow, sometimes alone
Vector Addition • Add components • p = ai + bj + ck • q = si + tj + uk • p + q = (a + s) i + (b + t) j + (c + u) k
Vector Subtraction • p – q = p + (-q) • vector inverse defined: • q = si + tj + uk • -q = (-s)i + (-t)j + (-u)k • p = ai + bj + ck • q = si + tj + uk • p – q = (a – s) i + (b – t) j + (c – u) k
Vector Multiplication • Dot product • magnitude of projection of one vector onto the other • Cross product • only defined for 3-vectors! • vector perpendicular to arguments, with magnitude equal to area of the spanned parallelogram
Dot product • p = ai + bj + ck • q = si + tj + uk • p ∙ q = a*s + b*t + c*u • scalar quantity • p ∙ q = |p| |q| cos θpq
Dot product applications • Basic use: projection of one vector onto another • Lighting: • classic diffuse shading: N∙L • Collisions: • amount of velocity in arbitrary direction • Vector reflection: R = V – 2 V ∙ N ( N/|N|)
Cross product • p = ai + bj + ck • q = si + tj + uk • p x q = (b*u – c*t)i + (c*s – a*u)j + (a*t – b*s)k • new vector perpendicular to both starting vectors • p x q = |p| |q| sin θpq n • Conventionally, right handed coordinate system used
Cross product applications • Obtain surface normal for triangle • use two vectors in plane, cross product is perpendicular • also note, can find winding order (front or back facing) • Calculate area of triangle • In physics, cross product appears regularly • torque = F x d • F = q v x B for charged particle in magnetic field