Miscellaneous Math Joshua Barczak CMSC 435 UMBC You
Miscellaneous Math Joshua Barczak CMSC 435 UMBC
You had better know… • Basic Algebra • The Quadratic Formula • Geometry and Trigonometry – SOHCAHTOA or however you learned it – Pathagorean theorem – Angles and lines • What “the matrix” is…
Today • Barrage of math facts useful to graphics – Vectors – Matrices – Lines/Planes – Triangles – Implicits
Vectors • N-vector Tuple of N of scalars – Arbitrary dimension – 2, 3, 4 are ubiquitous in graphics
Vectors • Vectors are arrows protruding from a point… – Direction – Magnitude z y x
Points • … and points are vectors from the origin – Direction from origin – Magnitude=Distance z y x
Spherical Coordinates • 2 angles + Distance Wikipedia
Vectors • Some definitions: – Orthogonal Perpendicular – Magnitude (Length): – Normalized Length=1 • Normalization – Divide by length
Surface Normals • Surface normal = – Normalized vector perendicular to some surface • Perpendicular to polygon plane • Perpendicular to curve tangent at some point N N
Arithmetic Commutative Distributive Associative
Vector Addition v u v v u u+v = v+u Put them end to end, then connect the dots… Order doesn’t matter….
Vector Subtraction • Subtracting vectors gives a vector between the two “tips” xb-xa V yb-ya A B
Point Subtraction • Subtracting points gives a vector from last to first, with first as its “origin”… P 1 P 0 V y 1 -y 0 x 1 -x 0
Vector Scaling au u yu ayu xu axu Scales vector length by a
Dot Product q u, v are orthogonal u, v are perpendicular cos(theta) = 0 u. v=0
Dot Product • Implications: – Same direction • u. v = |u||v| • Length is sqrt(x. x) – Opposite direction • u. v = -|u||v| – Normalized vectors • Cosine of angle – Same sign, same side… N
Dot Product u v’ v Dot products can be used to project onto other vectors
Dot Product • More useful facts (a, b, c vectors. x, y scalars) Just like multiplication… If you’re queasy about dot products, go home and prove all these….
Basis Vectors • All vectors can be written as linear combinations of other vectors
Basis Vectors • Basis: – “Linearly independent set of vectors that span a space” • One is not a weighted sum of the others • Orthogonal basis – Basis S. T. all vectors are perpendicular • Orthonormal basis – Orthogonal basis with unit-length vectors
Basis Vectors • Vectors are always relative to some basis – The “Default” basis vectors are the coordinate axes… Y+ A X+ C B D
Basis Vectors • …. and a point is relative to an origin AND some basis vectors Y+ A X+ C B D
Coordinate System • Basis Vectors + Origin – Basis is a “span” – Sometimes basis is orthonormal Y Z X • Cartesian Coordinates – Origin is 0, 0, 0 – Basis Vectors • X+, Y+, Z+ Wikipedia
Change of Basis • To write a vector v in terms of new basis vectors Bx and By we…. xv By v yv Bx This will become very important later…
Change of Basis • …project it onto each basis vector. Bx, By are the new coordinate axes… x’ v’ By y’ Bx This will become very important later…
Change of Coordinate System • To switch coordinate systems we… By P O Bx This will become very important later…
Change of Coordinate System • …write P in terms of new origin, then…. By P’ O Bx This will become very important later…
Change of Coordinate System • …project onto new basis vectors By Q O Bx This will become very important later…
Change of Coordinate System • To go back out, add scaled basis vectors to origin… By P Q O Bx This will become very important later…
Handedness Y Y Y Z Z X X Wikipedia Y Z Y Y Z X Wikipedia, Reflected X Z X
Cross Product Wikipedia
Cross Product • Perpendicular to inputs • Length is area of parallelogram b axb q a
Cross Product • If a, b are orthonormal, axb is normalized • If a, b have same or opposite direction, axb is zero • Also: – Anticommutative – Distributive – NOT associative b axb q a
Cross Product • More potentially useful facts…
Building an Orthogonal Basis B B A (Ax. B)x. A A Ax. B B Ax. B
2 D “Cross Product” r 1 r 0 Signed area of Parallelogram. Negative Vectors are clockwise Positive Vectors are counterclockwise
2 D “Cross Product” • Application: – Given two points, which side of their line is a third point on? B C A
2 D “Sidedness” • Use 2 D Cross product: – Positive Left – Negative Right – Zero Co-linear B C A
Matrices N row vectors M column vectors Nx. M scalars… If you have not taken your red pill, do so NOW…
Matrix Determinant(2 x 2) Didn’t we see this already…? c 1 c 0 Signed area of Parallelogram. Negative Vectors are clockwise Positive Vectors are counterclockwise Positive Identity matrix
Matrix Determinant (3 x 3) Signed volume of that thing Positive Right handed basis Negative Left handed basis Wikipedia
Matrix Multiplication
Matrix Multiplication • …is just a bunch of dot products
Matrix/Vector Multiplication
Matrix/Vector Multiplication • …. is also a bunch of dot products – This IS change of basis • Projection onto row/column vectors
Matrix Inverse • If rows form an orthonormal basis, Inverse equals transpose • Square matrix is invertible if it has nonzero determinant – Zero determinant Zero area/volume – Vectors do not span the full space… If det(M)=0, it goes flat…
Linear Interpolation • In-betweening… s A A B t B C t=0. 25 t=0. 75 D s t=1
Implicit 2 D Lines • You should know slope-intercept • Lines also have an implicit form (A, B) (x 2, y 2) (x 1, y 1)
Implicit 2 D Lines • Point-Line Distance – Plug point into line equation – Result is scaled by length of [A, B] – To “normalize” line, divide A, B, C by normal length Positive Here (A, B) (x 2, y 2) Negative Here (x 1, y 1)
3 D Planes • Planes are analogous to 2 D Lines • Plug in points for signed distance – Positive “in front” – Negative “behind” – 0 On plane The rain in Spain…
3 D Planes • Plane from point and normal N P P 1
3 D Planes • Plane from 3 Points – Cross Product N P 3 P 2 P 1
Triangle Area • This again… C – Sign indicates vertex order… • Positive: A, B, C counterclockwise – In 3 D: Use magnitude of cross product… B A
Point-In-Triangle Test • Method 1: Y – Three determinant tests. Check signs… P (blue) (red) (green) X Z
Point-In-Triangle Test • Method 2: B – Extract line equations • See earlier slides – Test signed distances P • Same sign Inside A C
Barycentric Coordinates g=0 • Ratios of areas a=0 g B (0, 1, 0) P a b b=0 Inside Triangle A (1, 0, 0) C (0, 0, 1)
Barycentric Coordinates • Or… – Edge equations normalized to opposite vertex… a=0 b=1 a=1 b=0 g=1
Barycentric Interpolation • Interpolation across triangle surface – Weight per-vertex values by barycentric coordinates
Implicit Surfaces • Surface – Set of all zeros of implicit function – “Inside” Negative – “Outside” Positive • Surface normal – Vector of partials • “Gradient” – Points in direction of greatest change in f
Implicit Surfaces …mmmmmm…. Formulii……
- Slides: 60