Linear algebra and geometric transformations in 2D
Computer Graphics CSE 167 Lecture 2 CSE 167: Computer Graphics
• Linear algebra – Vectors – Matrices • Points as vectors • Geometric transformations in 2D – Homogeneous coordinates
CSE 167, Winter 2018 2 Vectors
• Represent magnitude and direction in multiple dimensions • Examples – Translation of a point – Surface normal vectors (vectors orthogonal to surface)
CSE 167, Winter 2018 3 Based on slides courtesy of Jurgen Schulze Vectors and arithmetic
Examples using Vectors are 3‐vectors column vectors
Vectors must be the same length
CSE 167, Winter 2018 4 Magnitude of a vector
• The magnitude of a vector is its norm
Example using 3‐vector
• A vector if magnitude 1 is called a unit vector • A vector can be unitized by dividing by its norm
CSE 167, Winter 2018 5 Dot product of two vectors
Angle between two vectors
CSE 167, Winter 2018 6 Cross product of two 3‐vectors
• The cross product of two 3‐vectors a and b results in another 3‐vector that is orthogonal (using right hand rule) to the two vectors
CSE 167, Winter 2018 7 Cross product of two 3‐vectors
CSE 167, Winter 2018 8 Matrices
• 2D array of numbers
A =
CSE 167, Winter 2018 9 Matrix addition
• Matrices must be the same size
• Matrix subtraction is similar
CSE 167, Winter 2018 10 Matrix‐scalar multiplication
CSE 167, Winter 2018 11 Matrix‐matrix multiplication
CSE 167, Winter 2018 12 Matrix‐vector multiplication
• Same as matrix‐matrix multiplication – Example: 3x3 matrix multiplied with 3‐vector
CSE 167, Winter 2018 13 Transpose
• AT is the matrix A flipped over its diagonal
– Example
• Vectors can also be transposed to convert between column and row vectors
– Example
CSE 167, Winter 2018 14 The identity matrix
CSE 167, Winter 2018 15 Matrix inverse
• The inverse of a square matrix M is a matrix M‐1 such that
• A square matrix has an inverse if and only if its determinant is nonzero • The inverse of a product of matrices is Example using three matrices
CSE 167, Winter 2018 16 Representing points using vectors
• 2D point
• 3D point
CSE 167, Winter 2018 17 Geometric transformations in 2D
• Operations on vectors (or points) – Translation – Linear transformation • Scale • Shear • Rotation • Any combination of these – Affine transformation • Linear transformation followed by translation
CSE 167, Winter 2018 18 2D translation
• Translation of vector v to v’ under translation t
CSE 167, Winter 2018 19 2D uniform scale
• Scale x and y the same
CSE 167, Winter 2018 20 2D nonuniform scale
• Scale x and y independently
CSE 167, Winter 2018 21 2D shear
• Shear in x direction (horizontal)
CSE 167, Winter 2018 22 2D rotation
• Positive angles rotate counterclockwise
where
CSE 167, Winter 2018 23 2D rotation about a point
CSE 167, Winter 2018 24 2D rotation about a point
1. Translate point 2. Rotate about 3. Translate origin to the origin the origin back to point
CSE 167, Winter 2018 25 2D rotation about a point
• This can be accomplished with one transformation matrix, if we use homogeneous coordinates • A 2D point using affine homogeneous coordinates is a 3‐vector with 1 as the last element
CSE 167, Winter 2018 26 2D translation using homogeneous coordinates • 2D translation using a 3x3 matrix
• Inverse of 2D translation is inverse of 3x3 matrix ‐ ‐
CSE 167, Winter 2018 27 2D rotation using homogeneous coordinates • 2D rotation using homogenous coordinates
CSE 167, Winter 2018 28 2D rotation about a point using homogeneous coordinates
‐ ‐
Important: transformation matrices are applied right to left CSE 167, Winter 2018 29 2D rotation about a point using homogeneous coordinates
‐ ‐
M
‐ where M ‐
CSE 167, Winter 2018 30