- Points, Vectors - A point is a position - A vector is a direction and a length - We often use something called "normalized" vectors, which have length = 1. This makes some of the math easier. - Basic arithmetic with points, vectors (P, Q, R = points, U, V, W = vectors) - Addition (componentwise) - vector + vector = vector, uses paralellogram rule - point + vector = point, translates the point - point + point = T@N#H% - You can't add points and have it make geometric sense - UNLESS! you do a weighted average, where the weights add up to 1 - t * point + (1 - t) * point = point - At t = 0, at first point - At t = 1, at second point - At t = 0.5, halfway between - At t = 0.25, 25% between - T can be negative too! - Called a LERP, for "linear interpolation". - Subtraction (componentwise) - vector - vector = vector, uses triangle rule - point - vector = point, translates the point backwards - point - point = vector, finds distance between points - Multiplication (componentwise) - Doesn't have any geometric meaning! - Multiplication (the DOT PRODUCT) - noted U . V = scalar (normal number) - Algebraic interpretation - U_x * V_x + U_y * V_y (in 2D) - U_x * V_x + U_y * V_y + U_z * V_z (in 3D) - Acts like you'd expect multiplication to - Associative (U . V) . W = U . (V . W) - Commutative U . V = V . U - Distributive (U + V) . W = U. W + V . W - Geometric meaning - |U| |V| cos t - VERY POWERFUL - if t = 90deg (vectors are perpendicular), will be zero - if t < 90deg (vectors point in same dir), will be positive - if t > 90deg (vectors point in opposite dir), will be negative - if t = 0deg (same vectors), then V . V = |V|^2 - THE DOT PRODUCT IS EXTREMELY USEFUL FOR MAKING GEOMETRIC MATH SIMPLER - Collide Circles from HW1 -- example - |(p_1 + t v_1) - (p_2 + t v_2)| = r_1 + r_2 |(p_1 + t v_1) - (p_2 + t v_2)|^2 = (r_1 + r_2)^2 |(p_1 - p_2) + t(v_1 - v_2)|^2 = (p_1 - p_2).(p_1 - p_2) = + 2t(p_1 - p_2).(v_1 - v_2) + t^2(v_1 - v_2).(v_1 - v_2) t^2 * (v_1 - v_2).(v_1 - v_2) = 0 + t * 2(p_1 - p_2).(v_1 - v_2) + (p_1 - p_2).(p_1 - p_2) - (r_1 + r_2)^2 - Projection - proj_V U, gets the vector that is U's part in the direction of V - proj_V U = V . U ----- V V . V - Note that if V is a unit vector (of length 1), then this simplifies to (V . U) V - Can use this to easily calculate the distance between a point and a line - Matrices - Algebraic definition - Use the dot product!!! - i'th row, j'th column is calculated with the dot product - Also follows MOST of the rules of multiplication - Associative, Distributive - NOT COMMUTATIVE - "anti-commutative", NM = trans( trans(M) trans(N) ) - Geometric meaining - Represent linear maps, transforming space - You can figure out what a matrix does entirely by looking at what it does to the X and Y axes - Matrices to remember - IDENTITY MATRIX | 1 0 | | 0 1 | - SCALE MATRIX | x 0 | | 0 y | - ROTATION MATRIX | cos t -sin t | | sin t cos t | - Note that inverse of rotation is the matrix transposed! - Homogenous coordinates - Add a "w" component, which should always be 0 or 1. If it is not 1, divide the vector by it to make it 1. - Homogenous matrices to remember - TRANSLATION MATRIX | 1 0 x | | 0 1 y | | 0 0 1 | - PROJECTION MATRIX (useful in 3D) | x 0 0 0 | | 0 y 0 0 | | 0 0 za zb | | 0 0 -1 0 | - x determines X fov - y determines Y fov - za, zb together determine the near Z and far Z planes