Math Fundamentals Maths revisit
Overview Vectors Coordinate systems Matrices Homogenous coordinates Lines Planes
Vector Used to represent In graphics, usually 2D, 3D, 4D quantities Points in space E.g. locations of objects, vertices of a triangle mesh Spatial directions E.g. orientation of the camera, surface normals In graphics, usually 2D, 3D, 4D quantities Quantity with direction and magnitude E.g. if we connect two points with a directed line segment Directed line segment has magnitude (its length) and direction (its orientation) No fixed position
Vectors Representation Vector operations Scalar multiplication Can have their lengths altered by multiplying with real numbers
Vectors Vector operations (cont.) Vector addition and subtraction Can combine using head-to-tail rule Inverse/negate
Vectors Can use a vector to move from one point to another (point-vector addition): P = Q + v Any two points define a vector from one point to the second (point-point subtraction): v = P – Q Unit vector Vector of magnitude = 1 normalisation
Vectors Vectors operations (cont.) Dot product E.g. [ax ay az ] • [bx by bz ] = axbx + ayby + azbz
Vectors Vectors operations (cont.) Vector cross product 3D vectors only Cross product results in a vector Length of resulting vector
Coordinate Systems Need a frame of reference to relate points and objects to our physical world E.g. where is a point? Can’t answer without a reference system
Coordinate Systems Handedness of the system Determined by Thumb: + x-axis Index finger: + y-axis Middle finger: + z-axis OpenGL: right-handed system DirectX: left-handed system
Matrices Transformations are central to 3D graphics Matrices Almost every pipeline stage involves a change of coordinate system Moving from one coordinate system to another requires the use of transformation matrices Matrices Rectangular grid of numbers arranged in rows and columns Dimensions rows x columns
Matrices Square matrices Same number of rows and columns Diagonal elements Elements where row and column index the same Identity matrix Diagonal elements = 1, all others 0 In some ways, what is 1 is for scalars M-1 M = I MI = IM = M
Matrices Transposition Flip the matrix diagonally Multiplying a matrix with a scalar
Matrices Multiplying two matrices AB ≠ BA AI = IA = A
Matrices Multiplying two matrices (cont.)
Matrices Multiplying two matrices (cont.)
Matrices Multiplying two matrices (cont.)
Homogenous Coordinates Homogenous coordinates are key to all computer graphics systems Points are typically represented by (x,y) or (x,y,z) Add a 3rd or 4th coordinate, w All standard transformations (rotation, translation, scaling) can be implemented with matrix multiplication using 3 x 3 or 4 x 4 matrices Hardware pipeline works with 4-dimensional representations
Lines and Rays A line extends infinitely in two directions A line segment is a finite portion of a line that has two endpoints A ray is half of a line that has an origin and extends infinitely in one direction Sometimes defined as a directed line segment (finite length)
Lines and Rays Parametric definition of a line segment with endpoints (x0, y0) and (x1, y1) x(t) = x0 + t ∆x y(t) = y0 + t ∆y In vector notation, p(t) = p0 + td Straightforward extension of r3D, add z(t) The ray starts at point p0 : (x0, y0, z0). p0 contains information about the position of the ray 0 ≤ t ≤ 1 ∆x = (x1 – x0) ∆y = (y1 – y0)
Plane A plane is a flat surface (3D), has no thickness, extends infinitely Equation of a plane ax + by + cz + d = 0 p = (x, y, z) A 3D point on a plane n = (a, b, c) Normal vector, perpendicular to the plane n.p + d = 0