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

Linear algebra and geometric transformations in 2D · 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

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Linear algebra and geometric transformations in 2D · 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

Linear algebra and geometric transformations in 2D

Computer GraphicsCSE 167Lecture 2

Page 2: Linear algebra and geometric transformations in 2D · 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

CSE 167: Computer Graphics

• Linear algebra– Vectors– Matrices

• Points as vectors• Geometric transformations in 2D

– Homogeneous coordinates

CSE 167, Winter 2018 2

Page 3: Linear algebra and geometric transformations in 2D · 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

Vectors

• Represent magnitude and direction in multiple dimensions

• Examples– Translation of a point– Surface normal vectors (vectors orthogonal to surface)

CSE 167, Winter 2018 3Based on slides courtesy of Jurgen Schulze

Page 4: Linear algebra and geometric transformations in 2D · 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

Vectors and arithmetic

CSE 167, Winter 2018 4

Examples using 3‐vectors

Vectors must be the same length

Vectors are column vectors

Page 5: Linear algebra and geometric transformations in 2D · 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

Magnitude of a vector

• The magnitude of a vector is its norm

• 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

Example using 3‐vector

Page 6: Linear algebra and geometric transformations in 2D · 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

Dot product of two vectors

CSE 167, Winter 2018 6

Angle between two vectors

Page 7: Linear algebra and geometric transformations in 2D · 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

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 2018 7

Page 8: Linear algebra and geometric transformations in 2D · 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

Cross product of two 3‐vectors

CSE 167, Winter 2018 8

Page 9: Linear algebra and geometric transformations in 2D · 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

Matrices

• 2D array of numbers

A =

CSE 167, Winter 2018 9

Page 10: Linear algebra and geometric transformations in 2D · 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

Matrix addition

• Matrices must be the same size

• Matrix subtraction is similar

CSE 167, Winter 2018 10

Page 11: Linear algebra and geometric transformations in 2D · 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

Matrix‐scalar multiplication

CSE 167, Winter 2018 11

Page 12: Linear algebra and geometric transformations in 2D · 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

Matrix‐matrix multiplication

CSE 167, Winter 2018 12

Page 13: Linear algebra and geometric transformations in 2D · 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

Matrix‐vector multiplication

• Same as matrix‐matrix multiplication– Example: 3x3 matrix multiplied with 3‐vector

CSE 167, Winter 2018 13

Page 14: Linear algebra and geometric transformations in 2D · 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

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

Page 15: Linear algebra and geometric transformations in 2D · 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

The identity matrix

CSE 167, Winter 2018 15

Page 16: Linear algebra and geometric transformations in 2D · 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

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

CSE 167, Winter 2018 16

Example using three matrices

Page 17: Linear algebra and geometric transformations in 2D · 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

Representing points using vectors

• 2D point

• 3D point

CSE 167, Winter 2018 17

Page 18: Linear algebra and geometric transformations in 2D · 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

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

Page 19: Linear algebra and geometric transformations in 2D · 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

2D translation

• Translation of vector v to v’ under translation t

CSE 167, Winter 2018 19

Page 20: Linear algebra and geometric transformations in 2D · 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

2D uniform scale

• Scale x and y the same

CSE 167, Winter 2018 20

Page 21: Linear algebra and geometric transformations in 2D · 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

2D nonuniform scale

• Scale x and y independently

CSE 167, Winter 2018 21

Page 22: Linear algebra and geometric transformations in 2D · 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

2D shear

• Shear in x direction (horizontal)

CSE 167, Winter 2018 22

Page 23: Linear algebra and geometric transformations in 2D · 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

2D rotation

• Positive angles rotate counterclockwise

CSE 167, Winter 2018 23

where

Page 24: Linear algebra and geometric transformations in 2D · 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

2D rotation about a point

CSE 167, Winter 2018 24

Page 25: Linear algebra and geometric transformations in 2D · 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

2D rotation about a point

CSE 167, Winter 2018 25

1. Translate point to the origin

2. Rotate about the origin

3. Translate origin back to point

Page 26: Linear algebra and geometric transformations in 2D · 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

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

Page 27: Linear algebra and geometric transformations in 2D · 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

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

Page 28: Linear algebra and geometric transformations in 2D · 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

2D rotation using homogeneous coordinates

• 2D rotation using homogenous coordinates

CSE 167, Winter 2018 28

Page 29: Linear algebra and geometric transformations in 2D · 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

2D rotation about a pointusing homogeneous coordinates

CSE 167, Winter 2018 29

Important: transformation matrices are applied right to left

Page 30: Linear algebra and geometric transformations in 2D · 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

2D rotation about a pointusing homogeneous coordinates

CSE 167, Winter 2018 30

M

where M‐