Linear transformations Affine transformations Transformations in 3D. Graphics 2011/2012, 4th quarter. Lecture 5: linear and affine transformations

Similar documents
Introduction to Matrices

3D Tranformations. CS 4620 Lecture 6. Cornell CS4620 Fall 2013 Lecture Steve Marschner (with previous instructors James/Bala)

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.

Geometric Transformation CS 211A

Section V.3: Dot Product

13 MATH FACTS a = The elements of a vector have a graphical interpretation, which is particularly easy to see in two or three dimensions.

Lecture 2 Matrix Operations

Chapter 17. Orthogonal Matrices and Symmetries of Space

Lecture L3 - Vectors, Matrices and Coordinate Transformations

9 MATRICES AND TRANSFORMATIONS

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 2. x n. a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2 a 31 a 32 a 3n b 3. a m1 a m2 a mn b m

Rotation Matrices and Homogeneous Transformations

2D Geometric Transformations

Vector Math Computer Graphics Scott D. Anderson

521493S Computer Graphics. Exercise 2 & course schedule change

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS

TWO-DIMENSIONAL TRANSFORMATION

MAT188H1S Lec0101 Burbulla

Unified Lecture # 4 Vectors

Problem Set 5 Due: In class Thursday, Oct. 18 Late papers will be accepted until 1:00 PM Friday.

Lectures notes on orthogonal matrices (with exercises) Linear Algebra II - Spring 2004 by D. Klain

Chapter 6. Linear Transformation. 6.1 Intro. to Linear Transformation

Linear Algebra Review. Vectors

Similarity and Diagonalization. Similar Matrices

Chapter 19. General Matrices. An n m matrix is an array. a 11 a 12 a 1m a 21 a 22 a 2m A = a n1 a n2 a nm. The matrix A has n row vectors

Lecture 2: Homogeneous Coordinates, Lines and Conics

A linear combination is a sum of scalars times quantities. Such expressions arise quite frequently and have the form

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

Lecture Notes 2: Matrices as Systems of Linear Equations

[1] Diagonal factorization

Lecture 3: Coordinate Systems and Transformations

Introduction to Matrices for Engineers

Review Jeopardy. Blue vs. Orange. Review Jeopardy

Name: Section Registered In:

Geometric Transformations

Introduction to Matrix Algebra

1 Symmetries of regular polyhedra

x1 x 2 x 3 y 1 y 2 y 3 x 1 y 2 x 2 y 1 0.

Affine Transformations

Linear Algebra Notes for Marsden and Tromba Vector Calculus

5. Orthogonal matrices

2D Geometrical Transformations. Foley & Van Dam, Chapter 5

Solution to Homework 2

Chapter 11 Equilibrium

Mathematics Course 111: Algebra I Part IV: Vector Spaces

x = + x 2 + x

December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS

LS.6 Solution Matrices

Linear Algebra Notes

Given a point cloud, polygon, or sampled parametric curve, we can use transformations for several purposes:

Physics 235 Chapter 1. Chapter 1 Matrices, Vectors, and Vector Calculus

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

Lecture 5: Singular Value Decomposition SVD (1)

5.3 The Cross Product in R 3

Section 5.3. Section 5.3. u m ] l jj. = l jj u j + + l mj u m. v j = [ u 1 u j. l mj

Basic CAD/CAM. CHAPTER 5: Geometric Transformation

Section Continued

L 2 : x = s + 1, y = s, z = 4s Suppose that C has coordinates (x, y, z). Then from the vector equality AC = BD, one has

MATH 304 Linear Algebra Lecture 18: Rank and nullity of a matrix.

A =

Vector and Matrix Norms

Math 215 HW #6 Solutions

1 VECTOR SPACES AND SUBSPACES

T ( a i x i ) = a i T (x i ).

Lecture notes on linear algebra

Math 241, Exam 1 Information.

Geometry for Computer Graphics

Solutions to Math 51 First Exam January 29, 2015

Content. Chapter 4 Functions Basic concepts on real functions 62. Credits 11

MATH10212 Linear Algebra. Systems of Linear Equations. Definition. An n-dimensional vector is a row or a column of n numbers (or letters): a 1.

Lecture 1: Schur s Unitary Triangularization Theorem

1 Introduction to Matrices

12.5 Equations of Lines and Planes

MATHEMATICS FOR ENGINEERS BASIC MATRIX THEORY TUTORIAL 2

MATH2210 Notebook 1 Fall Semester 2016/ MATH2210 Notebook Solving Systems of Linear Equations... 3

CS 4204 Computer Graphics

Notes on Orthogonal and Symmetric Matrices MENU, Winter 2013

Lecture 7. Matthew T. Mason. Mechanics of Manipulation. Lecture 7. Representing Rotation. Kinematic representation: goals, overview

Notes on Determinant

Computer Graphics Labs

Geometric Camera Parameters

Inner Product Spaces and Orthogonality

LINEAR ALGEBRA W W L CHEN

MATH APPLIED MATRIX THEORY

18.06 Problem Set 4 Solution Due Wednesday, 11 March 2009 at 4 pm in Total: 175 points.

The Dot and Cross Products

Linear algebra and the geometry of quadratic equations. Similarity transformations and orthogonal matrices

Linear Programming. March 14, 2014

7.4. The Inverse of a Matrix. Introduction. Prerequisites. Learning Style. Learning Outcomes

Geometric description of the cross product of the vectors u and v. The cross product of two vectors is a vector! u x v is perpendicular to u and v

Recall the basic property of the transpose (for any A): v A t Aw = v w, v, w R n.

Chapter 7. Permutation Groups

160 CHAPTER 4. VECTOR SPACES

Recall that two vectors in are perpendicular or orthogonal provided that their dot

Geometry of Vectors. 1 Cartesian Coordinates. Carlo Tomasi

LINES AND PLANES CHRIS JOHNSON

MAT 200, Midterm Exam Solution. a. (5 points) Compute the determinant of the matrix A =

Eigenvalues, Eigenvectors, Matrix Factoring, and Principal Components

Matrix Representations of Linear Transformations and Changes of Coordinates

( ) which must be a vector

Transcription:

Lecture 5 Linear and affine transformations

Vector transformation: basic idea Definition Examples Finding matrices Compositions of transformations Transposing normal vectors Multiplication of an n n matrix with a vector (i.e. a n 1 matrix): ( a11 a In 2D: 12 a 21 a 22 ) ( ) x = y ( ) a11 x + a 12 y a 21 x + a 22 y a 11 a 12 a 13 x a 11 x + a 12 y + a 13 z In 3D: a 21 a 22 a 23 y = a 21 x + a 22 y + a 23 z a 31 a 32 a 33 z a 31 x + a 32 y + a 33 z The result is a (transformed) vector.

Example: scaling Linear transformations Definition Examples Finding matrices Compositions of transformations Transposing normal vectors To scale with a factor two with respect to the origin, we apply the matrix ( ) 2 0 0 2 to a vector: ( ) ( ) 2 0 x 0 2 y = ( ) 2x + 0y = 0x + 2y ( ) 2x 2y

Linear transformations Definition Examples Finding matrices Compositions of transformations Transposing normal vectors A function T : R n R m is called a linear transformation if it satisfies 1 T ( u + v) = T ( u) + T ( v) for all u, v R n. 2 T (c v) = ct ( v) for all v R n and all scalars c. Or (alternatively), if it satisfies T (c 1 u + c 2 v) = c 1 T ( u) + c 2 T ( v) for all u, v R n and all scalars c 1, c 2. v T (v) u + v u T (u + v) T (u) Linear transformations can be represented by matrices

Example: scaling Linear transformations Definition Examples Finding matrices Compositions of transformations Transposing normal vectors We already saw scaling by a factor of 2. In general, a matrix ( a11 0 0 a 22 ) scales the i-th coordinate of a vector by the factor a ii 0, i.e. ( a11 0 0 a 22 ) ( ) x = y ( ) a11 x + 0y = 0x + a 22 y ( ) a11 x a 22 y

Example: scaling Linear transformations Scaling does not have to be uniform. Here, we scale with a factor one half in x-direction, and three in y-direction: ( 1 ) ( ) 2 0 x 0 3 y = ( 1 2 x ) 3y Definition Examples Finding matrices Compositions of transformations Transposing normal vectors Q: what is the inverse of this matrix?

Example: scaling Linear transformations Definition Examples Finding matrices Compositions of transformations Transposing normal vectors Using Gaussian elimination to calculate the inverse of a matrix: ( 1 2 0 1 0 0 3 0 1 ) (Gaussian elimination) ( 1 0 2 0 0 1 0 1 3 )

Example: projection Linear transformations We can also use matrices to do orthographic projections, for instance, onto the Y -axis: ( ) ( ) 0 0 x 0 1 y = ( ) 0 y Definition Examples Finding matrices Compositions of transformations Transposing normal vectors Q: what is the inverse of this matrix?

Example: reflection Linear transformations Reflection in the line y = x boils down to swapping x- and y-coordinates: ( ) ( ) 0 1 x 1 0 y = ( ) y x Definition Examples Finding matrices Compositions of transformations Transposing normal vectors Q: what is the inverse of this matrix?

Example: shearing Linear transformations Definition Examples Finding matrices Compositions of transformations Transposing normal vectors Shearing in x-direction pushes things sideways : ( ) ( ) 1 1 x 0 1 y = ( ) x + y y We can also push things upwards with ( ) ( ) 1 0 x 1 1 y = ( x ) x + y

Example: shearing Linear transformations Definition Examples Finding matrices Compositions of transformations Transposing normal vectors General case for shearing in x-direction: ( ) ( ) 1 s x 0 1 y ( ) x + sy = y And its inverse operation: ( ) ( ) 1 s x 0 1 y ( ) x sy = y

Example: rotation Linear transformations Definition Examples Finding matrices Compositions of transformations Transposing normal vectors To rotate 45 about the origin, we apply the matrix ( 2 2 2 2 2 2 2 2 ) = 2 2 ( ) 1 1 1 1 Note: 2 2 = cos 45 = sin 45, so this is the same as ( cos 45 sin 45 ) sin 45 cos 45

Example: rotation Linear transformations Definition Examples Finding matrices Compositions of transformations Transposing normal vectors General case for a counterclockwise rotation about an angle φ around the origin: ( ) cos φ sin φ sin φ cos φ And for clockwise rotation: ( ) cos φ sin φ sin φ cos φ

Finding matrices Linear transformations Definition Examples Finding matrices Compositions of transformations Transposing normal vectors Applying matrices is pretty straightforward, but how do we find the matrix for a given linear transformation? ( ) a11 a Let A = 12 a 21 a 22 Q: what values do we have to assign to the a ij s to achieve a certain transformation?

Finding matrices Linear transformations Definition Examples Finding matrices Compositions of transformations Transposing normal vectors Let s apply some transformations to the base vectors b 1 = (1, 0) and b 2 = (0, 1) of the carthesian coordinates system, e.g. Scaling (factors a, b 0): Shearing (x-dir., factor s): Reflection (in line y = x): Rotation (countercl., 45 ): ( ) ( ) a 0 x 0 b y ( ) ( ) 1 s x 0 1 y ( ) ( ) 0 1 x 1 0 y 2 2 = = = ( ) ax by ( ) x + sy y ( ) y x ( ) ( ) 1 1 x 1 1 y = 2 2 ( ) x y x + y

Finding matrices Linear transformations Definition Examples Finding matrices Compositions of transformations Transposing normal vectors Aha! The column vectors of a transformation matrix are the images of the base vectors! That gives us an easy method of finding the matrix for a given linear transformation. Why? Because matrix multiplication is a linear transformation.

Finding matrices Linear transformations Definition Examples Finding matrices Compositions of transformations Transposing normal vectors Remember: T is a linear transformation if and only if T (c 1 u + c 2 v) = c 1 T ( u) + c 2 T ( v) Let s look at carthesian coordinates, where each vector w can be represented as a linear combination of the base vectors b 1, b 2 : w = ( ) x = x y ( ) 1 + y 0 ( ) 0 1 If we apply a linear transformation T to this vector, we get: ( ) ( ) ( ) ( ) ( ) x 1 0 1 0 T ( ) = T (x + y ) = xt ( ) + yt ( ) y 0 1 0 1

Finding matrices: example Rotation (counterclockwise, angle φ): Definition Examples Finding matrices Compositions of transformations Transposing normal vectors ( cos φ ) sin φ sin φ cos φ For example for the first base vector b 1 :

Example: reflection and scaling Definition Examples Finding matrices Compositions of transformations Transposing normal vectors Multiple transformations can be combined into one. Here, we first do a reflection in the line y = x, and then we scale with a factor 5 in x-direction, and a factor 2 in y-direction: ( ) ( ) ( ) 5 0 0 1 x = 0 2 1 0 y ( 0 5 2 0 ) ( ) x y Remember: matrix multiplication is associative, i.e. A(Bx) = (AB)x.

Example: reflection and scaling Definition Examples Finding matrices Compositions of transformations Transposing normal vectors But: Matrix multiplication is not commutative, i.e. in general AB BA, for example: ( ) ( ) ( ) 5 0 0 1 x = 0 2 1 0 y ( ) ( ) ( ) 0 1 5 0 x = 1 0 0 2 y Mind the order! ( 0 5 2 0 ( 0 2 5 0 ) ( ) x = y ) ( ) x = y ( ) 5y 2x ( ) 2y 5x

Transposing normal vectors Definition Examples Finding matrices Compositions of transformations Transposing normal vectors Unfortunately, normal vectors are not always transformed properly. E.g. look at shearing, where tangent vectors are correctly transformed but normal vectors not. To transform a normal vector n correctly under a given linear transformation A, we have to apply the matrix (A 1 ) T. Why?

Transposing normal vectors Definition Examples Finding matrices Compositions of transformations Transposing normal vectors We know that tangent vectors are tranformed correctly: A t = t A. But this is not necessarily true for normal vectors: A n n A. Goal: find matrix N A that transforms n correctly, i.e. N A n = n N where n N is the correct normal vector of the transformed surface. We know that n T t = 0. Hence, we can also say that n T I t = 0 which is is the same as n T A 1 A t = 0

Transposing normal vectors Definition Examples Finding matrices Compositions of transformations Transposing normal vectors Because A t = t A is our correctly transformed tangent vector, we have n T A 1 t A = 0 Because their scaler product is 0, n T A 1 must be orthogonal to it. So, the vector we are looking for must be n T N = nt A 1. Because of how matrix multiplication is defined, this is a transposed vector. But we can rewrite this to n N = ( n T A 1 ) T. And if you remember that (AB) T = B T A T, we get n N = (A 1 ) T n

Problem...... and solution: homogeneous coordinates More complex transformations So now we know how to determine matrices for a given transformation. Let s try another one: Q: what is the matrix for a rotation of 90 about the point (2, 1)?

Problem...... and solution: homogeneous coordinates More complex transformations We can form our transformation by composing three simpler transformations: Translate everything such that the center of rotation maps to the origin. Rotate about the origin. Revert the translation from the first step. Q: but what is the matrix for a translation?

Problem...... and solution: homogeneous coordinates More complex transformations Translation is not a linear transformation. With linear transformations we get: ( ) ( ) a11 a Ax = 12 x = a 21 a 22 y But we need something like: ( x + ) xt y + y t ( a11 x + ) a 12 y a 21 x + a 22 y We can do this with a combination of linear transformations and translations called affine transformations.

Problem...... and solution: homogeneous coordinates Homogeneous coordinates Observation: Shearing in 2D smells a lot like translation in 1D...

Problem...... and solution: homogeneous coordinates Homogeneous coordinates... and shearing in 3D smells like translation in 2D (... and shearing in 4D... )

Problem...... and solution: homogeneous coordinates Homogeneous coordinates in 2D: basic idea

Problem...... and solution: homogeneous coordinates Homogeneous coordinates in 2D: basic idea We see: by adding a 3rd dimension to our 2D space, we can add a constant value to the first two coordinates by matrix multiplication. x x + x t M y = y + y t d d That s exactly what we want (for the first 2 coordinates). But how does the matrix M look like? And how are we dealing with this 3rd coordinate?

Problem...... and solution: homogeneous coordinates Homogeneous coordinates Shearing in 3D based on the z-coordinate is a simple generalization of 2D shearing: 1 0 x t x x + x t d 0 1 y t y = y + y t d 0 0 1 d d Notice that we didn t make any assumption about d,...

Problem...... and solution: homogeneous coordinates Homogeneous coordinates: matrices... so we can use, for example, d = 1: 1 0 x t x x + x t 0 1 y t y = y + y t 0 0 1 1 1

Problem...... and solution: homogeneous coordinates Homogeneous coordinates: points Translations in 2D can be represented as shearing in 3D by looking at the plane z = 1. By representing all our 2D points (x, y) by 3D vectors (x, y, 1), we can translate them about (x t, y t ) using the following 3D shearing matrix: 1 0 x t x x + x t 0 1 y t y = y + y t 0 0 1 1 1

Problem...... and solution: homogeneous coordinates Homogeneous coordinates: vectors But can we translate a vector? No! (Remember: vectors are defined by their length and direction.) Hence, we have to represent a vector differently, i.e. by (x, y, 0): 1 0 x t x x 0 1 y t y = y 0 0 1 0 0

Problem...... and solution: homogeneous coordinates Homogeneous coordinates (i.e. linear transformations and translations) can be done with simple matrix multiplication if we add homogeneous coordinates, i.e. (in 2D): a third coordinate z = 1 x to each location: y 1 a third coordinate z = 0 x to each vector: y 0 a third row (0... 0 1) to each matrix:...... 0... 0 1

Problem...... and solution: homogeneous coordinates : points vs. vectors Scaling and moving a location/point (or an object ): 1 0 x t s 1 0 0 x s 1 0 x t x s 1x + x t 0 1 y t 0 s 2 0 y = 0 s 2 y t y = s 2y + y t 0 0 1 0 0 1 1 0 0 1 1 1 With the same matrix, we scale (but not move!) a vector: s 1 0 x t x s 1x 0 s 2 y t y = s 2y 0 0 1 0 0

Problem...... and solution: homogeneous coordinates : example What is the matrix for reflection in the line y = x + 5? Idea: move everything to the origin, reflect, and the move everything back.

Problem...... and solution: homogeneous coordinates : example 1. Translation of y = x + 5 to y = x 1 0 x t x x + x t 0 1 y t y = y + y t 0 0 1 1 1 2. Reflection on y = x: ( 0 ) 1 1 0 3. Translate y = x back to y = x + 5 0 1. 1 0.... 1 0. 0 1. 0 0 1 1 0. 0 1. 0 0 1..................

Problem...... and solution: homogeneous coordinates So, the matrix for reflection in the line y = x + 5 is 0 1 5 1 0 5 0 0 1 But what is the significance of the columns of the matrix?

Problem...... and solution: homogeneous coordinates The last column vector is the image of the origin after applying the affine transformation (Remember: The other columns are the image of the base vectors under the linear transformation) (Also remember: The coordinates in the last row are called homogeneous coordinates) 0 1 5 1 0 5 0 0 1

Moving up a dimension Rotations in 3D Reflections in 3D Linear transformations in 3D In general, linear transformations in 3D are a straightforward extension of their 2D counterpart. We have already seen an example: shearing in x y direction 1 0 d x 0 1 d y 0 0 1 Or in general 1 d x2 d x3 d y1 1 d y3 0 0 1

Moving up a dimension Rotations in 3D Reflections in 3D in 3D Homogeneous coordinates (and therewith affine transformations) in 3D are also a straightforward generalization from 2D. We just have to use 4 4 matrices now: a 11 a 12 a 13 0 Matrices: a 21 a 22 a 23 0 a 31 a 32 a 33 0 0 0 0 1 x x points: y z and vectors: y z 1 0

Moving up a dimension Rotations in 3D Reflections in 3D For scaling, we have three scaling factors on the diagonal of the matrix. s x 0 0 0 s y 0 0 0 s z Shearing can be done in either x-, y-, or z-direction (or a combination thereof). For example, shearing in x-direction: 1 d x2 d x3 x x + d y y + d z z 0 1 0 y = y 0 0 1 z z

Moving up a dimension Rotations in 3D Reflections in 3D We see: transformations in 3D are very similar to those in 2D. Scaling and shearing are straightforward generalizations of the 2D cases. Reflection is done with respect to planes Rotation is done about directed lines.

Moving up a dimension Rotations in 3D Reflections in 3D : rotations Q: What is the matrix for a rotation of angle φ about the z-axis? Rotation in 2D (x y-plane): ( ) cos φ sin φ sin φ cos φ

Moving up a dimension Rotations in 3D Reflections in 3D : rotations Q: What is the matrix for a rotation of angle φ about the z-axis? Rotation in 2D (x y-plane): ( cos φ ) sin φ sin φ cos φ Rotation in 3D around z-axis: cos φ sin φ 0 sin φ cos φ 0 0 0 1

Moving up a dimension Rotations in 3D Reflections in 3D : rotations Q: What is the matrix for a rotation of angle φ about the directed line (0, 1, 2) + t(3, 0, 4) t > 0?

Moving up a dimension Rotations in 3D Reflections in 3D : rotations We need a 3D transformation that rotates around an arbitrary vector w. How can we do that? Idea: 1 Rotate vector w to z-axis 2 Do 3D rotation around z-axis 3 Rotate everything back to original position

Moving up a dimension Rotations in 3D Reflections in 3D : rotations We already know how to rotate around the z-axis: cos φ sin φ 0 sin φ cos φ 0 0 0 1

Moving up a dimension Rotations in 3D Reflections in 3D : rotations But how do we get the other 2 rotation matrices? cos φ sin φ 0? sin φ cos φ 0? 0 0 1 Rotating everything back to it s original position after we have done the rotation is easy. Remember that the columns of the rotation matrix represent the images of the carthesian basis vectors under the transformation! x u x v x w cos φ sin φ 0 y u y v y w sin φ cos φ 0? z u z v z w 0 0 1

Moving up a dimension Rotations in 3D Reflections in 3D : rotations Now all we still need is the original rotation matrix x u x v x w cos φ sin φ 0 y u y v y w sin φ cos φ 0? z u z v z w 0 0 1 But that s just the inverse of the other rotation matrix. Note: if we assume that u = v = w = 1 we don t even need to calculate it, because the inverse of an orthogonal matrix is always its transposed! x u x v x w cos φ sin φ 0 x u y u z u y u y v y w sin φ cos φ 0 x v y v z v z u z v z w 0 0 1 x w y w z w

Moving up a dimension Rotations in 3D Reflections in 3D : rotations Hmm, but we only have the vector w. How do we get a whole coordinates system u, v, w? w

Moving up a dimension Rotations in 3D Reflections in 3D : rotations Notice that such a rotation is not unique. (And it doesn t have to be as long as the two rotation matrices are correct.)

Moving up a dimension Rotations in 3D Reflections in 3D : reflections Q: What is the matrix for reflection in XY -plane? What happens to a random point (x, y, z) in 3D when we reflect it on the XY -plane?

Moving up a dimension Rotations in 3D Reflections in 3D : reflections Hence, the matrix for reflection in XY -plane is: 1 0 0 0 1 0 0 0 1

Moving up a dimension Rotations in 3D Reflections in 3D : reflections Q: What is the matrix for reflection in XY -plane? Q: What is the matrix for reflection in the plane 3x + 4y 12z = 0?

Moving up a dimension Rotations in 3D Reflections in 3D : reflections Q: What is the matrix for reflection in XY -plane? Q: What is the matrix for reflection in the plane 3x + 4y 12z = 0?

Moving up a dimension Rotations in 3D Reflections in 3D : reflections Q: What is the matrix for reflection in XY -plane? Q: What is the matrix for reflection in the plane 3x + 4y 12z = 0? Q: What is the matrix for reflection in the plane 3x + 4y 12z = 11?