38
Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2

Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Linear algebra and geometric transformations in 2D

Computer Graphics

CSE 167

Lecture 2

Page 2: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

CSE 167: Computer Graphics

• Linear algebra

– Vectors

– Matrices

• Points as vectors

• Geometric transformations in 2D

– Homogeneous coordinates

CSE 167, Winter 2020 2

Page 3: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Vectors

• Represent magnitude and direction in multiple dimensions

• Examples

– Translation of a point

– Surface normal vectors (vectors orthogonal to surface)

CSE 167, Winter 2020 3

Page 4: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Vectors and arithmetic

• Addition and subtraction

CSE 167, Winter 2020 4

Vectors must be the same length

Vectors are column vectors

Page 5: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Vectors and arithmetic

• Negate vector

• Vector-scalar multiply

CSE 167, Winter 2020 5

Page 6: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Vectors and arithmetic

CSE 167, Winter 2020 6

Examples using 3-vectors

Page 7: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Vector transpose

CSE 167, Winter 2020 7

Column vector

Example using 3-vector

Row vector

Page 8: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Magnitude of a vector

• The magnitude of a vector is its norm

CSE 167, Winter 2020 8

Example using 3-vector

Page 9: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Unit vector

• A vector of magnitude 1 is called a unit vector

• A vector can be unitized by dividing by its norm

• The norm of a unit vector is 1

CSE 167, Winter 2020 9

Page 10: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Dot product of two vectors

• Angle between two vectors

CSE 167, Winter 2020 10

Example using 3-vector

Page 11: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Magnitude of a vector revisited

• The magnitude of a vector is its norm

CSE 167, Winter 2020 11

Using dot product

Page 12: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Cross product of two 3-vectors

• The cross product of two 3-vectors a and bresults in another 3-vector that is orthogonal (using right hand rule) to the two vectors

CSE 167, Winter 2020 12

Page 13: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Cross product of two 3-vectors

• Angle between two vectors

CSE 167, Winter 2020 13

Page 14: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Matrices

• 2D array of numbers

CSE 167, Winter 2020 14

m rows and n columns

Page 15: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Matrix addition and subtraction

• Matrices must be the same size

CSE 167, Winter 2020 15

Page 16: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Matrix-scalar multiplication

CSE 167, Winter 2020 16

Page 17: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Matrix-vector multiplication

CSE 167, Winter 2020 17

Result is vector of length m (i.e., number of rows in matrix)

Matrix of m rows and n columnstimes

vector of length n

Number of matrix columns must equal vector length

Page 18: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Matrix-vector multiplication

CSE 167, Winter 2020 18

Example using 3x3 matrix

and3-vector

Page 19: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Cross product of two 3-vectors revisited

CSE 167, Winter 2020 19

Using matrix-vector multiply

Page 20: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Matrix-matrix multiplication

CSE 167, Winter 2020 20

Number of left matrix columns must equal

number of right matrix rows

m-by-p matrix times p-by-n matrix

Result is m-by-n matrix

Page 21: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Matrix transpose

• The transpose of a product of matrices is the transpose of each matrix multiplied in reverse order

CSE 167, Winter 2020 21

m rows and n columns n rows and m columns

Flipped over the diagonal

Example using three matrices

Page 22: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

The identity matrix

CSE 167, Winter 2020 22

Page 23: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Matrix inverse

• The inverse of a square matrix A is a matrix A-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 the inverse of each matrix multiplied in reverse order

CSE 167, Winter 2020 23

Example using three matrices

Page 24: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Representing points using vectors

• 2D point

• 3D point

CSE 167, Winter 2020 24

Page 25: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

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 2020 25

Page 26: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

2D translation

• Translation of vector x to x’ under translation t

CSE 167, Winter 2020 26

Page 27: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

2D uniform scale

• Scale x and y the same

CSE 167, Winter 2020 27

Page 28: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

2D nonuniform scale

• Scale x and y independently

CSE 167, Winter 2020 28

Page 29: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

2D shear

• Shear in x direction (horizontal)

CSE 167, Winter 2020 29

Page 30: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

2D rotation

• Positive angles rotate counterclockwise

CSE 167, Winter 2020 30

Page 31: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

Inverse 2D rotation

• Positive angles rotate counterclockwise

• Negative angles rotate clockwise

CSE 167, Winter 2020 31

Page 32: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

2D rotation about a point

CSE 167, Winter 2020 32

?

Page 33: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

2D rotation about a point

CSE 167, Winter 2020 33

1. Translate point to the origin

2. Rotate about the origin

3. Translate origin back to point

Page 34: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

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 2020 34

Page 35: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

2D translation using homogeneous coordinates

• 2D translation using a 3x3 matrix

• Inverse of 2D translation is inverse of 3x3 matrix

CSE 167, Winter 2020 35

-

-

Page 36: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

2D rotation using homogeneous coordinates

• 2D rotation using homogenous coordinates

CSE 167, Winter 2020 36

Page 37: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

2D rotation about a pointusing homogeneous coordinates

CSE 167, Winter 2020 37

-

-

Important: transformation matrices are applied right to left

Page 38: Linear algebra and geometric transformations in 2D · 2020-01-08 · Linear algebra and geometric transformations in 2D Computer Graphics CSE 167 Lecture 2. CSE 167: Computer Graphics

2D rotation about a pointusing homogeneous coordinates

CSE 167, Winter 2020 38

-

-

M

where M

-

-