Practical Linear Algebra: A Geometry Toolbox Fourth Edition Chapter 4: Changing Shapes: Linear Maps in 2D
Gerald Farin & Dianne Hansford
A K Peters/CRC Press www.farinhansford.com/books/pla
c 2021
Farin & Hansford Practical Linear Algebra 1 / 55 Outline
1 Introduction to Linear Maps in 2D 2 Skew Target Boxes 3 The Matrix Form 4 Linear Spaces 5 Scalings 6 Reflections 7 Rotations 8 Shears 9 Projections 10 Application: Free-form Deformations 11 Areas and Linear Maps: Determinants 12 Composing Linear Maps 13 More on Matrix Multiplication 14 Matrix Arithmetic Rules 15 WYSK
Farin & Hansford Practical Linear Algebra 2 / 55 Introduction to Linear Maps in 2D
2D linear maps (rotation and scaling) applied repeatedly to a square Geometry has two parts 1 description of the objects 2 how these objects can be changed (transformed) Transformations also called maps May be described using the tools of matrix operations: linear maps
Matrices first introduced by H. Grassmann in 1844 Became basis of linear algebra
Farin & Hansford Practical Linear Algebra 3 / 55 Skew Target Boxes
Revisit unit square to a rectangular target box mapping Examine part of mapping that is a linear map
Unit square defined by e1 and e2 Vector v in [e1, e2]-system defined as
v = v1e1 + v2e2
v is now mapped to a vector v′ by
′ v = v1a1 + v2a2
Duplicates the [e1, e2]-geometry in the [a1, a2]-system This is a change of basis The two equations on this page are linear combinations
Farin & Hansford Practical Linear Algebra 4 / 55 Skew Target Boxes
Example: [a1, a2]-coordinate system: origin and 2 2 a1 = a2 = − 1 4 1/2 Given v = in [e , e ]-system 1 1 2
′ 1 2 2 1 v = + 1 − = − 2 × 1 × 4 9/2
1/2 v′ has components with 1 respect to [a1, a2]-system ′ 1 v has components − with 9/2 respect to [e1, e2]-system Farin & Hansford Practical Linear Algebra 5 / 55 The Matrix Form
Components of a subscripted vector written with a double subscript
a1,1 a1 = a2,1
The vector component index precedes the vector subscript
′ Components for v in [e1, e2]-system expressed as
1 1 2 2 − = + 1 − 9/2 2 × 1 × 4
Write this linear combination in matrix notation: 1 2 2 1/2 − = − 9/2 1 4 1
2 2 matrix: 2 rows and 2 columns defined as vectors a and a × 1 2 Farin & Hansford Practical Linear Algebra 6 / 55 The Matrix Form
In general:
′ a a v v = 1,1 1,2 1 = Av a2,1 a2,2v2 A is a 2 2 matrix × Elements a1,1 and a2,2 form the diagonal
v′ is the image of v v is the pre-image of v′ v′ is in the range of the map v is in the domain of the map
Farin & Hansford Practical Linear Algebra 7 / 55 The Matrix Form
Product Av has two components:
v1a1,1 + v2a1,2 Av = v1a1 + v2a2 = v a , + v a , 1 2 1 2 2 2 Each component obtained as a dot product between the corresponding row of the matrix and v Example:
0 1 1 0 1+ 1 4 4 − − = ×− − × = − 2 4 4 2 1 + 4 4 14 ×− ×
Column space of A: all v′ formed as linear combination of the columns of A
Farin & Hansford Practical Linear Algebra 8 / 55 The Matrix Form
[e1, e2]-system can be interpreted as a matrix with columns e1 and e2:
1 0 [e , e ] 2 2 identity matrix 1 2 ≡ 0 1 ×
Falk’s scheme – A neat way to write matrix-times-vector: 2 1/2 2 2 3 − 1 4 4
Here: (2 2)(2 1) results in (2 1) vector × × × Interior dimensions (both 2) must be identical Outer dimensions (2 and 1) indicate the resulting vector or matrix size
Farin & Hansford Practical Linear Algebra 9 / 55 The Matrix Form
Matrix addition: a a b b a + b a + b 1,1 1,2 + 1,1 1,2 = 1,1 1,1 1,2 1,2 a2,1 a2,2 b2,1 b2,2 a2,1 + b2,1 a2,2 + b2,2
Matrices must be of the same dimensions
Distributive law Av + Bv = (A + B)v
Farin & Hansford Practical Linear Algebra 10 / 55 The Matrix Form
Transpose matrix denoted by AT Formed by interchanging the rows and columns of A:
1 2 T 1 3 A = − then A = 3 5 2 5 − May think of a vector v as a matrix:
1 T v = − then v = 1 4 4 −
Identities: T T T [A + B] = A + B TT T T A = A and [cA] = cA
Farin & Hansford Practical Linear Algebra 11 / 55 The Matrix Form
Symmetric matrix: A = AT Example: 5 8 8 1 No restrictions on diagonal elements All other elements equal to element about the diagonal with reversed indices For a 2 2 matrix: a , = a , × 2 1 1 2 2 2 zero matrix: × 0 0 0 0
Farin & Hansford Practical Linear Algebra 12 / 55 The Matrix Form
Matrix rank: number of linearly independent column (row) vectors
For 2 2 matrix columns define an [a , a ]-system × 1 2 Full rank = 2: a1 and a2 are linearly independent Rank deficient: matrix that does not have full rank
If a1 and a2 are linearly dependent then matrix has rank 1 Also called a singular matrix Only matrix with rank zero is zero matrix Rank of A and AT are equal.
Farin & Hansford Practical Linear Algebra 13 / 55 Linear Spaces
2D linear maps act on vectors in 2D linear spaces Also known as 2D vector spaces Standard operations in a linear space are addition and scalar multiplication of vectors
′ v = v1a1 + v2a2 linearity property Linear maps – matrices – characterized by preservation of linear
combinations: A(au + bv)= aAu + bAv. Let’s break this statement down into the two basic elements: scalar multiplication and addition
Farin & Hansford Practical Linear Algebra 14 / 55 Linear Spaces
Matrices preserve scalings Example:
1 1/2 A = − 0 1/2 − 1 1 u = v = − 2 4 A(cu)= cAu Let c = 2 1 1/2 1 − 2 0 1/2 × 2 − 1 1/2 1 0 = 2 − = × 0 1/22 2 − − Farin & Hansford Practical Linear Algebra 15 / 55 Linear Spaces
Matrices preserve sums (distributive law):
A(u + v)= Au + Av
Farin & Hansford Practical Linear Algebra 16 / 55 Linear Spaces
Matrices preserve linear combinations A(3u + 2v)
1 1/2 1 1 = − 3 + 2 − 0 1/2 2 4 − 6 = 3Au + 2Av 7 − 1 1/2 1 = 3 − 0 1/22 − 1 1/2 1 +2 − − 0 1/2 4 − 6 = 7 − Farin & Hansford Practical Linear Algebra 17 / 55 Scalings
Uniform scaling:
′ 1/2 0 v /2 v = v = 1 0 1/2 v2/2
Farin & Hansford Practical Linear Algebra 18 / 55 Scalings
s 0 1/2 0 General scaling: v′ = 1,1 v Example: v′ = v 0 s2,2 0 2
Scaling affects the area of the object: — Scale by s1,1 in e1-direction, then area changes by a factor s1,1 — Similarly for s2,2 and e2-direction Total effect: factor of s1,1s2,2 Action of matrix: action ellipse
Farin & Hansford Practical Linear Algebra 19 / 55 Reflections
Special scaling:
′ 1 0 v v = v = 1 0 1 v − − 2 v reflected about e1-axis or the line x1 = 0 Reflection maps each vector about a line through the origin
Farin & Hansford Practical Linear Algebra 20 / 55 Reflections
Reflection about line x1 = x2:
′ 0 1 v v = v = 2 1 0 v1 Reflections change the sign of the area due to a change in orientation — Rotate e1 into e2: move in a counterclockwise — Rotate a1 into a2: move in a clockwise
Farin & Hansford Practical Linear Algebra 21 / 55 Reflections
Reflection?
′ 1 0 v = − v 0 1 − Check a1 rotate to a2 orientation: counterclockwise — same as e1, e2 orientation This is a 180◦ rotation
Action ellipse: circle
Farin & Hansford Practical Linear Algebra 22 / 55 Rotations
Rotate e1 and e2 around the origin to
′ cos α ′ sin α e = and e = − 1 sin α 2 cos α
These are the column vectors of the rotation matrix cos α sin α R = − sin α cos α
Farin & Hansford Practical Linear Algebra 23 / 55 Rotations
Rotation matrix for α = 45◦:
√2/2 √2/2 R = − √2/2 √2/2
Rotations: special class of transformations called rigid body motions Action ellipse: circle Rotations do not change areas
Farin & Hansford Practical Linear Algebra 24 / 55 Shears
Map a rectangle to a parallelogram Example:
0 ′ d v = v = 1 1 −→ 1
A shear in matrix form: d 1 d 0 1 = 1 1 0 1 1
Application: generate italic fonts from standard ones.
Farin & Hansford Practical Linear Algebra 25 / 55 Shears
Shear along the e1-axis applied to an arbitrary vector:
′ 1 d v v + v d v = 1 1 = 1 2 1 0 1 v2 v2
Farin & Hansford Practical Linear Algebra 26 / 55 Shears
Shear along the e2-axis:
′ 1 0 v v v = 1 = 1 d2 1v2 v1d2 + v2
Farin & Hansford Practical Linear Algebra 27 / 55 Shears
What is the shear that achieves
v ′ v v = 1 v = 1 ? v2 −→ 0
A shear parallel to the e2-axis:
′ v 1 0 v v = 1 = 1 0 v /v 1v − 2 1 2 Shears do not change areas (See rectangle to parallelogram sketch: both have the same base and the same height)
Farin & Hansford Practical Linear Algebra 28 / 55 Projections
Parallel projections: all vectors are projected in a parallel direction 2D: all vectors are projected onto a line Example:
3 1 0 3 = 0 0 01
Orthogonal projection: angle of incidence with the line is 90◦ Otherwise: oblique projection Perspective projection: projection direction is not constant — not a linear map
Farin & Hansford Practical Linear Algebra 29 / 55 Projections
Orthogonal projections important for best approximation Oblique projections important to applications in fields such as computer graphics and architecture
Main property of a projection: reduces dimensionality Action ellipse: straight line segment which is covered twice
Farin & Hansford Practical Linear Algebra 30 / 55 Projections
Construction: Choose unit vector u to define a line onto which to project Projections of e1 and e2 are column vectors of matrix A
u e1 a1 = · u = u1u u 2 T A = u1u u2u = uu uk ke a = · 2 u = u u 2 u 2 2 k k
u
Example: u = [cos 30◦ sin 30◦]T
Farin & Hansford Practical Linear Algebra 31 / 55 Projections
T Projection matrix A = u1u u2u = uu Columns of A linearly dependent rank one ⇒ Map reduces dimensionality area after map is zero ⇒ Projection matrix is idempotent: A = AA Geometrically: once a vector projected onto a line, application of same projection leaves result unchanged
1/√2 0.5 0.5 Example: u = then A = 1/√2 0.5 0.5
Farin & Hansford Practical Linear Algebra 32 / 55 Projections
Action of projection matrix on a vector x:
T Ax = uu x = (u x)u · Same result as orthogonal projections in Chapter 2
Let y be projection of x onto u then x = y + y⊥
T T ⊥ Ax = uu y + uu y
Since uTy = y and uTy⊥ = 0 k k Ax = y u k k
Farin & Hansford Practical Linear Algebra 33 / 55 Application: Free-form Deformations
Change the shape of an object, deforming it into a different shape Special effects, animations, or create unique designs based on simple ones Demonstrate the idea with a rotation matrix Choose angle θ then rotate each vertex vi with
cos(di θ) sin(di θ) Ri = − where di = vi sin(di θ) cos(di θ) || ||
Left to right: θ = 0◦, 45◦, 180◦, 360◦
Farin & Hansford Practical Linear Algebra 34 / 55 Application: Color Interpolation
Sierpinski triangle is generated by repeatedly subdividing an input triangle Each of the three input vertices is assigned a color: c1, c2, c3 (Actually 3D vectors for red, green, and blue components) Every other vertex color c computed using its barycentric coordinates (b1, b2, b3) with respect to the input triangle
c = b1c1 + b2c2 + b3c3 This is the basic idea behind smooth shading in computer graphics
Farin & Hansford Practical Linear Algebra 35 / 55 Areas and Linear Maps: Determinants
2D linear map takes [e1, e2] to [a1, a2] How does linear map affect area?
area(e1, e2) = 1 (Square spanned by [e1, e2]) P = area of parallelogram spanned by [a1, a2] P = 2T
Farin & Hansford Practical Linear Algebra 36 / 55 Areas and Linear Maps: Determinants
Area T of triangle formed by a1 and a2:
T = a , a , T T T 1 1 2 2 − 1 − 2 − 3 Observe that 1 T = a , a , 1 2 1 1 2 1 1 T = (a , a , )(a , a , ) 2 2 1 1 − 1 2 2 2 − 2 1 1 T = a , a , 3 2 1 2 2 2 1 1 T = a , a , a , a , 2 1 1 2 2 − 2 1 2 2 1 P = a , a , a , a , 1 1 2 2 − 1 2 2 1
Farin & Hansford Practical Linear Algebra 37 / 55 Areas and Linear Maps: Determinants
P: (signed) area of the parallelogram spanned by A = [a1, a2] This is the determinant of A Notation: det A or A | |
a1,1 a1,2 A = = a1,1a2,2 a1,2a2,1 | | a2,1 a2,2 −
Farin & Hansford Practical Linear Algebra 38 / 55 Areas and Linear Maps: Determinants
Determinant characterizes a linear map: If A = 1 then linear map does not change areas | | If 0 A < 1 then linear map shrinks areas ≤ | | If A = 0 then matrix is rank deficient | | If A > 1 then linear map expands areas | | If A < 0 then linear map changes the orientation of objects | | 1 5 = (1)(1) (5)(0) = 1 0 1 −
1 0 = (1)( 1) (0)(0) = 1 0 1 − − − −
0.5 0.5 = (0.5)(0.5) (0.5)(0.5) = 0 0.5 0.5 −
Farin & Hansford Practical Linear Algebra 39 / 55 Areas and Linear Maps: Determinants
ca , a = c a , a = c A | 1 2| | 1 2| | |
If one column of A scaled by c then A’s determinant scaled by c Sketch: c = 2
Farin & Hansford Practical Linear Algebra 40 / 55 Areas and Linear Maps: Determinants
ca , ca = c2 a , a = c2 A | 1 2| | 1 2| | |
If both columns of A scaled by c then A’s determinant scaled by c2 Sketch: c = 1/2
Farin & Hansford Practical Linear Algebra 41 / 55 Areas and Linear Maps: Determinants
Two 2D vectors whose determinant is positive: right-handed Standard example: e1 and e2 Two 2D vectors whose determinant is negative are called left-handed
Area sign change when columns interchanged: a , a = a , a | 1 2| −| 2 1| Verified using the definition of a determinant:
a , a = a , a , a , a , | 2 1| 1 2 2 1 − 2 2 1 1
Farin & Hansford Practical Linear Algebra 42 / 55 Composing Linear Maps
Matrix product used to compose linear maps:
′ v = Av
′′ ′ v = Bv = B(Av)= BAv = Cv b b a a b a + b a b a + b a C = 1,1 1,2 1,1 1,2 = 1,1 1,1 1,2 2,1 1,1 1,2 1,2 2,2 b2,1 b2,2a2,1 a2,2 b2,1a1,1 + b2,2a2,1 b2,1a1,2 + b2,2a2,2 th th Element ci,j computed as dot product of B’s i row and A’s j column
Farin & Hansford Practical Linear Algebra 43 / 55 Composing Linear Maps
Example:
2 1 2 0 2 v = , A = − , B = − 1 0 3 3 1 − − ′ 1 2 2 4 v Av == − = − 0 3 1 3 − − ′′ ′ 0 2 4 6 v = Bv = − − = 3 1 3 9 − − Compute v′′ using the matrix product BA:
0 2 1 2 0 6 C = BA = − − = − 3 1 0 3 3 3 − − Verify that v′′ = Cv
Farin & Hansford Practical Linear Algebra 44 / 55 Composing Linear Maps
Falk’s method: Neat way to arrange two matrices when forming their product
1 2 − 0 3 0 2 3− 1 3 − 1 2 − 0 3 0 2 0 6 − − 3 1 3 3 − −
Farin & Hansford Practical Linear Algebra 45 / 55 Composing Linear Maps
Linear map composition is order dependent
Top: rotate by 120◦, then reflect about the (rotated) e -axis − 1 Bottom: reflect, then rotate Matrix products differs significantly from products of real numbers: Matrix products are not commutative AB = BA 6 Some maps do commute – example: 2D rotations Farin & Hansford Practical Linear Algebra 46 / 55 Composing Linear Maps
Rank of a composite map:
rank(AB) min rank(A), rank(B) ≤ { } Matrix multiplication does not increase rank
Special composition: idempotent matrix A = AA or A = A2 Thus Av = AAv
Farin & Hansford Practical Linear Algebra 47 / 55 More on Matrix Multiplication
Vectors as matrices: uTv = u v · 3 3 Example: Let u = and v = − 4 6 T u v = u v = 15 ·
T T T (u v) = v u T T T 3 T (u v) = 3 4 − = [15] = 15 6 T 3 v u = 3 6 = [15] = 15 − 4
Farin & Hansford Practical Linear Algebra 48 / 55 More on Matrix Multiplication
T T T (AB) = B A
T T a a b b c c (AB) = 1,1 1,2 1,1 1,2 = 1,1 1,2 a2,1 a2,2b2,1 b2,2 c2,1 c2,2
T T T T T T b1,1 b1,2 a1,1 a1,2 c1,1 c1,2 B A = T T T T = b2,1 b2,2a2,1 a2,2 c2,1 c2,2
T Since bi,j = bj,i identical dot product calculated to form c1,2
Farin & Hansford Practical Linear Algebra 49 / 55 More on Matrix Multiplication
Determinant of a product matrix
AB = A B | | | || | B scales objects by B and A scales objects by A | | | | Composition of the maps scales by the product of the individual scales Example: 1/2 0 4 0 A = B = 0 1/2 0 4 A = 1/4 A scales down | | ⇒ B = 16 B scales up | | ⇒
2 0 AB = AB = A B = 4 scales up 0 2 | | | || | ⇒
Farin & Hansford Practical Linear Algebra 50 / 55 More on Matrix Multiplication
Exponents for matrices: Ar = A . . . A · · · · r times | {z } Some rules:
Ar+s = Ar As Ars = (Ar )s A0 = I
Farin & Hansford Practical Linear Algebra 51 / 55 Matrix Arithmetic Rules
Matrix sizes must be compatible for operations to be performed matrix addition: matrices to have the same dimensions • matrix multiplication: “inside” dimensions to be equal • Given: m r matrix A and r n matrix B × × C = AB is permissible since inside dimension r is shared Resulting matrix C dimension m n ×
Farin & Hansford Practical Linear Algebra 52 / 55 Matrix Arithmetic Rules
Commutative Law for Addition: A + B = B + A
Associative Law for Addition: A + (B + C) = (A + B)+ C
No Commutative Law for Multiplication: AB = BA 6 Associative Law for Multiplication: A(BC) = (AB)C
Distributive Law: A(B + C)= AB + AC
Distributive Law: (B + C)A = BA + CA
Farin & Hansford Practical Linear Algebra 53 / 55 Matrix Arithmetic Rules
Rules involving scalars a, b: Rules involving the transpose: a(B + C)= aB + aC (A + B)T = AT + BT (a + b)C = aC + bC (bA)T = bAT (ab)C = a(bC) (AB)T = BTAT T a(BC) = (aB)C = B(aC) AT = A
Farin & Hansford Practical Linear Algebra 54 / 55 WYSK
linear symmetric action ellipse determinant combination matrix reflections signed area matrix form rank of a rotations matrix matrix pre-image and multiplication rigid body image rank deficient motions composite map domain and singular matrix shears non- range linear space or commutative projections column space vector space property of parallel matrix identity matrix subspace projection multiplication matrix addition linearity oblique transpose of a property distributive law projection product or m scalings of matrices transpose dyadic matrix matrix rules of matrix idempotent arithmetic map Farin & Hansford Practical Linear Algebra 55 / 55