730 likes | 880 Views
Animation and Games Development. 242-515 , Semester 1 , 2014-2015. Objective to give some background on the course. 7. Basic Maths. Overview. Vectors Matricies The Dot Product The Cross Product Transformations as Matricies Multiple Coordinate Spaces Models in a Scene Graph.
E N D
Animation and Games Development 242-515, Semester 1, 2014-2015 • Objective • to give some background on the course 7. Basic Maths
Overview • Vectors • Matricies • The Dot Product • The Cross Product • Transformations as Matricies • Multiple Coordinate Spaces • Models in a Scene Graph
1. Vectors • A vector is a magnitude(size) and a direction. • drawn as an arrow
Two vectors V and W are added by placing the beginning of W at the end of V • Subtraction reverses the second vector W V V + W W –W V V – W V
Triangle Rule for Subtraction • Place c and d tail-to-tail. • d – c is the vector from the head of c to the head of d
Vector Magnitude • The magnitude of a vector is a scalar (a number):
Normalization • A normalized vector always has unit length. • To normalize a non-zero vector, divide by its magnitude.
Normalization as a Diagram unit circle
2. Matrices • A matrix is an array of numbers arranged in rows and columns • A matrix with n rows and m columns is an nm matrix • M is a 2 3 matrix • If n = m, the matrix is a square matrix
The transpose of a matrix M is denoted MT and has its rows and columns exchanged:
An n-dimensional vector V can be thought of as an n 1 columnmatrix: • Or a 1 nrow matrix:
Matrix Multiplication • The entries of the product of two matricies A and B are calculated by: • The number of columns in Amust equal the number of rows in B. • If A is a nm matrix, and B is an mp matrix, then AB is an np matrix.
In three dimensions, the product of a matrix and a column vector looks like:
Identity Matrix In For any nn matrix M, the product with the identity matrix is M itself • InM = M • MIn = M
Invertible • An nn matrix M is invertible if there exists another matrix G such that • The inverse of M is denoted M-1
Determinant • The determinant of a square matrix M is denoted det M or |M| • A matrix is invertible if its determinant is not zero. • For a 2 2 matrix,
Inverse • Explicit formulas exist for matrix inverses • These are good for small matrices, but other methods are generally used for larger matrices • In computer graphics, we usually deal with 2 2, 3 3, and a special form of 4 4 matrices
3. The Dot Product • The dot product is a product between two vectors that produces a magnitude (a number). • The dot product between twon-dimensional vectors V and W is given by • In three dimensions,
Dot product a· b is the magnitude of the projection of the b vector onto the a vector.
The dot product equation: • a is the angle between the two vectors • That's why the dot product is 0 between perpendicular vectors • If V and W are unit vectors, the dot product is 1 for parallel vectors pointing in the same direction, -1 for opposite
Dot Product for Finding Angles • The dot product can be used to find the angle between two vertors a and b. • First normalize a and b. • The angle between them is cos-1â . b ^
A Line as a Vector • A line in 3D space can be represented by • S is a point on the line, and V is the direction along which the line runs. R is a point on the line, t is a magnitude. R(t) = S + t V V t R S
Distance to a Line • Distance d from a point P to the line R(t)= S + t V P d S V
Use Pythagorean theorem: • Taking square root, • If V is unit length, then V 2 = 1
4. The Cross Product • The cross product between two vectors a and b produces a vector (a x b) which is perpendicular to both.
The cross product between V and W is • One way of remembering this equation is as the determinant:
It can also be expressed as a matrix-vector product • The perpendicularity property means that:
The cross product equation is: • This is equal to the area of the parallelogram formed by V and W: V ||V|| sin a a W
b a
What about the axb Direction? • Does the vector a x bpoint up or down from the plane of a and b? • Place the tail of b at the head of a. • Using your right hand, curl your fingers in the direction of the vectors. • Your thumb points in the direction of a x b
Reversing the order of the vectors negates the cross product: • the cross product is anti-commutative • If a x b = 0, then a is parallel to b.
5. Transformations as Matricies • A complex transformation can be built by combining simple transformations, of the types: • translations • scaling • rotations • Transformations are combined by multiplying their matrices together.
2D Translation (x+dx, y+dy) y y (x, y) dy x x dx (0,0)
2D Scaling • Resizes an object in each dimension about origin y y (sxx, syy) (x, y) x x
2D Rotation • Rotate counter-clockwise about the origin by angle y y (x', y') (x, y) x x
Homogenous Transformation Matricies • An 4x4 homogenous matrix can store 3D transformations. • This makes matrix inversion and combinations of transformations simpler. • It also makes it possible to define perspective transformations.
3D Translation Translation by (Δx, Δy, Δz):
3D Scaling Scaling about the origin
3D Rotations • z-axis rotation • Rotates about the z-axis through the angle q
Combining Transformations • The combined 4 4 homogenenous matrix is very common in computer graphics: • R is a 3 3 rotation matrix, and T is a translation vector