Introduction to Computer Graphics CS 445 / 645 Lecture 5 Transformations Transformations M.C. Escher...

Post on 22-Dec-2015

223 views 3 download

Tags:

Transcript of Introduction to Computer Graphics CS 445 / 645 Lecture 5 Transformations Transformations M.C. Escher...

Introduction to Computer GraphicsCS 445 / 645

Lecture 5Lecture 5

TransformationsTransformations

Lecture 5Lecture 5

TransformationsTransformationsM.C. Escher – Smaller and Smaller (1956)

Modeling Transformations

Specify transformations for objects Specify transformations for objects

• Allows definitions of objects in own coordinate systemsAllows definitions of objects in own coordinate systems

• Allows use of object definition multiple times in a sceneAllows use of object definition multiple times in a scene

– Remember how OpenGL provides a transformation Remember how OpenGL provides a transformation stack because they are so frequently reusedstack because they are so frequently reused

Chapter 5 from Hearn and BakerChapter 5 from Hearn and Baker

Specify transformations for objects Specify transformations for objects

• Allows definitions of objects in own coordinate systemsAllows definitions of objects in own coordinate systems

• Allows use of object definition multiple times in a sceneAllows use of object definition multiple times in a scene

– Remember how OpenGL provides a transformation Remember how OpenGL provides a transformation stack because they are so frequently reusedstack because they are so frequently reused

Chapter 5 from Hearn and BakerChapter 5 from Hearn and Baker

H&B Figure 109

Overview

2D Transformations2D Transformations

• Basic 2D transformationsBasic 2D transformations

• Matrix representationMatrix representation

• Matrix compositionMatrix composition

3D Transformations3D Transformations

• Basic 3D transformationsBasic 3D transformations

• Same as 2DSame as 2D

2D Transformations2D Transformations

• Basic 2D transformationsBasic 2D transformations

• Matrix representationMatrix representation

• Matrix compositionMatrix composition

3D Transformations3D Transformations

• Basic 3D transformationsBasic 3D transformations

• Same as 2DSame as 2D

2D Modeling Transformations

ScaleRotate

Translate

ScaleTranslate

x

y

World Coordinates

ModelingCoordinates

2D Modeling Transformations

x

y

World Coordinates

ModelingCoordinates

Let’s lookat this indetail…

2D Modeling Transformations

x

y

ModelingCoordinates

Initial locationat (0, 0) withx- and y-axesaligned

2D Modeling Transformations

x

y

ModelingCoordinates

Scale .3, .3Rotate -90

Translate 5, 3

2D Modeling Transformations

x

y

ModelingCoordinates

Scale .3, .3Rotate -90

Translate 5, 3

2D Modeling Transformations

x

y

ModelingCoordinates

Scale .3, .3Rotate -90

Translate 5, 3

World Coordinates

Scaling

ScalingScaling a coordinate means multiplying each of its a coordinate means multiplying each of its components by a scalarcomponents by a scalar

Uniform scalingUniform scaling means this scalar is the same for all means this scalar is the same for all components:components:

ScalingScaling a coordinate means multiplying each of its a coordinate means multiplying each of its components by a scalarcomponents by a scalar

Uniform scalingUniform scaling means this scalar is the same for all means this scalar is the same for all components:components:

2

Non-uniform scalingNon-uniform scaling: different scalars per component:: different scalars per component:

How can we represent this in matrix form?How can we represent this in matrix form?

Non-uniform scalingNon-uniform scaling: different scalars per component:: different scalars per component:

How can we represent this in matrix form?How can we represent this in matrix form?

Scaling

X 2,Y 0.5

Scaling

Scaling operation:Scaling operation:

Or, in matrix form:Or, in matrix form:

Scaling operation:Scaling operation:

Or, in matrix form:Or, in matrix form:

by

ax

y

x

'

'

y

x

b

a

y

x

0

0

'

'

scaling matrix

2-D Rotation

(x, y)

(x’, y’)

x’ = x cos() - y sin()y’ = x sin() + y cos()

2-D Rotationx = r cos ()y = r sin ()x’ = r cos ( + )y’ = r sin ( + )

Trig Identity…x’ = r cos() cos() – r sin() sin()y’ = r sin() sin() + r cos() cos()

Substitute…x’ = x cos() - y sin()y’ = x sin() + y cos()

(x, y)

(x’, y’)

2-D Rotation

This is easy to capture in matrix form:This is easy to capture in matrix form:

Even though sin(Even though sin() and cos() and cos() are nonlinear functions ) are nonlinear functions of of ,,• x’ is a linear combination of x and yx’ is a linear combination of x and y

• y’ is a linear combination of x and yy’ is a linear combination of x and y

This is easy to capture in matrix form:This is easy to capture in matrix form:

Even though sin(Even though sin() and cos() and cos() are nonlinear functions ) are nonlinear functions of of ,,• x’ is a linear combination of x and yx’ is a linear combination of x and y

• y’ is a linear combination of x and yy’ is a linear combination of x and y

y

x

y

x

cossin

sincos

'

'

Basic 2D TransformationsTranslation:Translation:

• x’ = x + tx’ = x + txx

• y’ = y + ty’ = y + tyy

Scale:Scale:

• x’ = x * sx’ = x * sxx

• y’ = y * sy’ = y * syy

Shear:Shear:

• x’ = x + hx’ = x + hxx*y*y

• y’ = y + hy’ = y + hyy*x*x

Rotation:Rotation:• x’ = x*cosx’ = x*cos - y*sin - y*sin

• y’ = x*siny’ = x*sin + y*cos + y*cos

Translation:Translation:

• x’ = x + tx’ = x + txx

• y’ = y + ty’ = y + tyy

Scale:Scale:

• x’ = x * sx’ = x * sxx

• y’ = y * sy’ = y * syy

Shear:Shear:

• x’ = x + hx’ = x + hxx*y*y

• y’ = y + hy’ = y + hyy*x*x

Rotation:Rotation:• x’ = x*cosx’ = x*cos - y*sin - y*sin

• y’ = x*siny’ = x*sin + y*cos + y*cos

Transformations can be combined

(with simple algebra)

Basic 2D TransformationsTranslation:Translation:

• x’ = x + tx’ = x + txx

• y’ = y + ty’ = y + tyy

Scale:Scale:

• x’ = x * sx’ = x * sxx

• y’ = y * sy’ = y * syy

Shear:Shear:

• x’ = x + hx’ = x + hxx*y*y

• y’ = y + hy’ = y + hyy*x*x

Rotation:Rotation:• x’ = x*cosx’ = x*cos - y*sin - y*sin

• y’ = x*siny’ = x*sin + y*cos + y*cos

Translation:Translation:

• x’ = x + tx’ = x + txx

• y’ = y + ty’ = y + tyy

Scale:Scale:

• x’ = x * sx’ = x * sxx

• y’ = y * sy’ = y * syy

Shear:Shear:

• x’ = x + hx’ = x + hxx*y*y

• y’ = y + hy’ = y + hyy*x*x

Rotation:Rotation:• x’ = x*cosx’ = x*cos - y*sin - y*sin

• y’ = x*siny’ = x*sin + y*cos + y*cos

Basic 2D TransformationsTranslation:Translation:

• x’ = x + tx’ = x + txx

• y’ = y + ty’ = y + tyy

Scale:Scale:

• x’ = x x’ = x * s* sxx

• y’ = y y’ = y * s* syy

Shear:Shear:

• x’ = x + hx’ = x + hxx*y*y

• y’ = y + hy’ = y + hyy*x*x

Rotation:Rotation:• x’ = x*cosx’ = x*cos - y*sin - y*sin

• y’ = x*siny’ = x*sin + y*cos + y*cos

Translation:Translation:

• x’ = x + tx’ = x + txx

• y’ = y + ty’ = y + tyy

Scale:Scale:

• x’ = x x’ = x * s* sxx

• y’ = y y’ = y * s* syy

Shear:Shear:

• x’ = x + hx’ = x + hxx*y*y

• y’ = y + hy’ = y + hyy*x*x

Rotation:Rotation:• x’ = x*cosx’ = x*cos - y*sin - y*sin

• y’ = x*siny’ = x*sin + y*cos + y*cos

x’ = x*sx

y’ = y*sy

x’ = x*sx

y’ = y*sy

(x,y)

(x’,y’)

Basic 2D Transformations

x’ = (x*sx)*cos - (y*sy)*siny’ = (x*sx)*sin + (y*sy)*cosx’ = (x*sx)*cos - (y*sy)*siny’ = (x*sx)*sin + (y*sy)*cos

(x’,y’)

Translation:Translation:

• x’ = x + tx’ = x + txx

• y’ = y + ty’ = y + tyy

Scale:Scale:

• x’ = x * sx’ = x * sxx

• y’ = y * sy’ = y * syy

Shear:Shear:

• x’ = x + hx’ = x + hxx*y*y

• y’ = y + hy’ = y + hyy*x*x

Rotation:Rotation:

• x’ = x*x’ = x*coscos - y* - y*sinsin

• y’ = x*y’ = x*sinsin + y* + y*coscos

Translation:Translation:

• x’ = x + tx’ = x + txx

• y’ = y + ty’ = y + tyy

Scale:Scale:

• x’ = x * sx’ = x * sxx

• y’ = y * sy’ = y * syy

Shear:Shear:

• x’ = x + hx’ = x + hxx*y*y

• y’ = y + hy’ = y + hyy*x*x

Rotation:Rotation:

• x’ = x*x’ = x*coscos - y* - y*sinsin

• y’ = x*y’ = x*sinsin + y* + y*coscos

Basic 2D TransformationsTranslation:Translation:

• x’ = x x’ = x + t+ txx

• y’ = y y’ = y + t+ tyy

Scale:Scale:

• x’ = x * sx’ = x * sxx

• y’ = y * sy’ = y * syy

Shear:Shear:

• x’ = x + hx’ = x + hxx*y*y

• y’ = y + hy’ = y + hyy*x*x

Rotation:Rotation:• x’ = x*cosx’ = x*cos - y*sin - y*sin

• y’ = x*siny’ = x*sin + y*cos + y*cos

Translation:Translation:

• x’ = x x’ = x + t+ txx

• y’ = y y’ = y + t+ tyy

Scale:Scale:

• x’ = x * sx’ = x * sxx

• y’ = y * sy’ = y * syy

Shear:Shear:

• x’ = x + hx’ = x + hxx*y*y

• y’ = y + hy’ = y + hyy*x*x

Rotation:Rotation:• x’ = x*cosx’ = x*cos - y*sin - y*sin

• y’ = x*siny’ = x*sin + y*cos + y*cos

x’ = ((x*sx)*cos - (y*sy)*sin) + tx

y’ = ((x*sx)*sin + (y*sy)*cos) + ty

x’ = ((x*sx)*cos - (y*sy)*sin) + tx

y’ = ((x*sx)*sin + (y*sy)*cos) + ty

(x’,y’)

Basic 2D TransformationsTranslation:Translation:

• x’ = x + tx’ = x + txx

• y’ = y + ty’ = y + tyy

Scale:Scale:

• x’ = x * sx’ = x * sxx

• y’ = y * sy’ = y * syy

Shear:Shear:

• x’ = x + hx’ = x + hxx*y*y

• y’ = y + hy’ = y + hyy*x*x

Rotation:Rotation:• x’ = x*cosx’ = x*cos - y*sin - y*sin

• y’ = x*siny’ = x*sin + y*cos + y*cos

Translation:Translation:

• x’ = x + tx’ = x + txx

• y’ = y + ty’ = y + tyy

Scale:Scale:

• x’ = x * sx’ = x * sxx

• y’ = y * sy’ = y * syy

Shear:Shear:

• x’ = x + hx’ = x + hxx*y*y

• y’ = y + hy’ = y + hyy*x*x

Rotation:Rotation:• x’ = x*cosx’ = x*cos - y*sin - y*sin

• y’ = x*siny’ = x*sin + y*cos + y*cos

x’ = ((x*sx)*cos - (y*sy)*sin) + tx

y’ = ((x*sx)*sin + (y*sy)*cos) + ty

x’ = ((x*sx)*cos - (y*sy)*sin) + tx

y’ = ((x*sx)*sin + (y*sy)*cos) + ty

Overview

2D Transformations2D Transformations

• Basic 2D transformationsBasic 2D transformations

• Matrix representationMatrix representation

• Matrix compositionMatrix composition

3D Transformations3D Transformations

• Basic 3D transformationsBasic 3D transformations

• Same as 2DSame as 2D

2D Transformations2D Transformations

• Basic 2D transformationsBasic 2D transformations

• Matrix representationMatrix representation

• Matrix compositionMatrix composition

3D Transformations3D Transformations

• Basic 3D transformationsBasic 3D transformations

• Same as 2DSame as 2D

Matrix Representation

Represent 2D transformation by a matrixRepresent 2D transformation by a matrix

Multiply matrix by column vectorMultiply matrix by column vector apply transformation to point apply transformation to point

Represent 2D transformation by a matrixRepresent 2D transformation by a matrix

Multiply matrix by column vectorMultiply matrix by column vector apply transformation to point apply transformation to point

yx

dcba

yx''

dcba

dycxy

byaxx

'

'

Matrix Representation

Transformations combined by multiplicationTransformations combined by multiplicationTransformations combined by multiplicationTransformations combined by multiplication

yx

lkji

hgfe

dcba

yx''

Matrices are a convenient and efficient way to represent a sequence of transformations!

2x2 Matrices

What types of transformations can be What types of transformations can be represented with a 2x2 matrix?represented with a 2x2 matrix?

What types of transformations can be What types of transformations can be represented with a 2x2 matrix?represented with a 2x2 matrix?

2D Identity?

yyxx

''

yx

yx

1001

''

2D Scale around (0,0)?

ysy

xsx

y

x

*'

*'

y

x

s

s

y

x

y

x

0

0

'

'

2x2 Matrices

What types of transformations can be What types of transformations can be represented with a 2x2 matrix?represented with a 2x2 matrix?

What types of transformations can be What types of transformations can be represented with a 2x2 matrix?represented with a 2x2 matrix?

2D Rotate around (0,0)?

yxyyxx

*cos*sin'*sin*cos'

y

x

y

x

cossin

sincos

'

'

2D Shear?

yxshy

yshxx

y

x

*'

*'

y

x

sh

sh

y

x

y

x

1

1

'

'

2x2 Matrices

What types of transformations can be What types of transformations can be represented with a 2x2 matrix?represented with a 2x2 matrix?

What types of transformations can be What types of transformations can be represented with a 2x2 matrix?represented with a 2x2 matrix?

2D Mirror about Y axis?

yyxx

''

yx

yx

1001

''

2D Mirror over (0,0)?

yyxx

''

yx

yx

1001

''

2x2 Matrices

What types of transformations can be What types of transformations can be represented with a 2x2 matrix?represented with a 2x2 matrix?

What types of transformations can be What types of transformations can be represented with a 2x2 matrix?represented with a 2x2 matrix?

2D Translation?

y

x

tyy

txx

'

'

Only linear 2D transformations can be represented with a 2x2 matrix

NO!

Linear TransformationsLinear transformations are combinations of …Linear transformations are combinations of …

• Scale,Scale,

• Rotation,Rotation,

• Shear, andShear, and

• MirrorMirror

Properties of linear transformations:Properties of linear transformations:

• Satisfies:Satisfies:

• Origin maps to originOrigin maps to origin

• Lines map to linesLines map to lines

• Parallel lines remain parallelParallel lines remain parallel

• Ratios are preservedRatios are preserved

• Closed under compositionClosed under composition

Linear transformations are combinations of …Linear transformations are combinations of …

• Scale,Scale,

• Rotation,Rotation,

• Shear, andShear, and

• MirrorMirror

Properties of linear transformations:Properties of linear transformations:

• Satisfies:Satisfies:

• Origin maps to originOrigin maps to origin

• Lines map to linesLines map to lines

• Parallel lines remain parallelParallel lines remain parallel

• Ratios are preservedRatios are preserved

• Closed under compositionClosed under composition

)()()( 22112211 pppp TsTsssT

y

x

dc

ba

y

x

'

'

Homogeneous Coordinates

Q: How can we represent translation as a 3x3 matrix?Q: How can we represent translation as a 3x3 matrix?Q: How can we represent translation as a 3x3 matrix?Q: How can we represent translation as a 3x3 matrix?

y

x

tyy

txx

'

'

Homogeneous Coordinates

Homogeneous coordinatesHomogeneous coordinates

• represent coordinates in 2 represent coordinates in 2 dimensions with a 3-vectordimensions with a 3-vector

Homogeneous coordinatesHomogeneous coordinates

• represent coordinates in 2 represent coordinates in 2 dimensions with a 3-vectordimensions with a 3-vector

1

coords shomogeneou y

x

y

x

Homogeneous coordinates seem unintuitive, but they Homogeneous coordinates seem unintuitive, but they make graphics operations make graphics operations muchmuch easier easier

Homogeneous coordinates seem unintuitive, but they Homogeneous coordinates seem unintuitive, but they make graphics operations make graphics operations muchmuch easier easier

Homogeneous Coordinates

Q: How can we represent translation as a 3x3 matrix?Q: How can we represent translation as a 3x3 matrix?

A: Using the rightmost column:A: Using the rightmost column:

Q: How can we represent translation as a 3x3 matrix?Q: How can we represent translation as a 3x3 matrix?

A: Using the rightmost column:A: Using the rightmost column:

100

10

01

y

x

t

t

ranslationT

y

x

tyy

txx

'

'

Translation

Example of translationExample of translation

Example of translationExample of translation

11100

10

01

1

'

'

y

x

y

x

ty

tx

y

x

t

t

y

x

tx = 2ty = 1

Homogeneous CoordinatesHomogeneous CoordinatesHomogeneous CoordinatesHomogeneous Coordinates

Homogeneous Coordinates

Add a 3rd coordinate to every 2D pointAdd a 3rd coordinate to every 2D point

• (x, y, w) represents a point at location (x/w, y/w)(x, y, w) represents a point at location (x/w, y/w)

• (x, y, 0) represents a point at infinity(x, y, 0) represents a point at infinity

• (0, 0, 0) is not allowed(0, 0, 0) is not allowed

Add a 3rd coordinate to every 2D pointAdd a 3rd coordinate to every 2D point

• (x, y, w) represents a point at location (x/w, y/w)(x, y, w) represents a point at location (x/w, y/w)

• (x, y, 0) represents a point at infinity(x, y, 0) represents a point at infinity

• (0, 0, 0) is not allowed(0, 0, 0) is not allowed

Convenient coordinate system to represent many useful transformations

1 2

1

2(2,1,1) or (4,2,2) or (6,3,3)

x

y

Basic 2D Transformations

Basic 2D transformations as 3x3 matricesBasic 2D transformations as 3x3 matricesBasic 2D transformations as 3x3 matricesBasic 2D transformations as 3x3 matrices

1100

0cossin

0sincos

1

'

'

y

x

y

x

1100

10

01

1

'

'

y

x

t

t

y

x

y

x

1100

01

01

1

'

'

y

x

sh

sh

y

x

y

x

Translate

Rotate Shear

1100

00

00

1

'

'

y

x

s

s

y

x

y

x

Scale

Affine Transformations

Affine transformations are combinations of …Affine transformations are combinations of …

• Linear transformations, andLinear transformations, and

• TranslationsTranslations

Properties of affine transformations:Properties of affine transformations:

• Origin does not necessarily map to originOrigin does not necessarily map to origin

• Lines map to linesLines map to lines

• Parallel lines remain parallelParallel lines remain parallel

• Ratios are preservedRatios are preserved

• Closed under compositionClosed under composition

Affine transformations are combinations of …Affine transformations are combinations of …

• Linear transformations, andLinear transformations, and

• TranslationsTranslations

Properties of affine transformations:Properties of affine transformations:

• Origin does not necessarily map to originOrigin does not necessarily map to origin

• Lines map to linesLines map to lines

• Parallel lines remain parallelParallel lines remain parallel

• Ratios are preservedRatios are preserved

• Closed under compositionClosed under composition

wyx

fedcba

wyx

100''

Projective Transformations

Projective transformations …Projective transformations …

• Affine transformations, andAffine transformations, and

• Projective warpsProjective warps

Properties of projective transformations:Properties of projective transformations:

• Origin does not necessarily map to originOrigin does not necessarily map to origin

• Lines map to linesLines map to lines

• Parallel lines do not necessarily remain parallelParallel lines do not necessarily remain parallel

• Ratios are not preservedRatios are not preserved

• Closed under compositionClosed under composition

Projective transformations …Projective transformations …

• Affine transformations, andAffine transformations, and

• Projective warpsProjective warps

Properties of projective transformations:Properties of projective transformations:

• Origin does not necessarily map to originOrigin does not necessarily map to origin

• Lines map to linesLines map to lines

• Parallel lines do not necessarily remain parallelParallel lines do not necessarily remain parallel

• Ratios are not preservedRatios are not preserved

• Closed under compositionClosed under composition

wyx

ihgfedcba

wyx

'''

Overview

2D Transformations2D Transformations

• Basic 2D transformationsBasic 2D transformations

• Matrix representationMatrix representation

• Matrix compositionMatrix composition

3D Transformations3D Transformations

• Basic 3D transformationsBasic 3D transformations

• Same as 2DSame as 2D

2D Transformations2D Transformations

• Basic 2D transformationsBasic 2D transformations

• Matrix representationMatrix representation

• Matrix compositionMatrix composition

3D Transformations3D Transformations

• Basic 3D transformationsBasic 3D transformations

• Same as 2DSame as 2D

Matrix Composition

Transformations can be combined by Transformations can be combined by matrix multiplicationmatrix multiplication

Transformations can be combined by Transformations can be combined by matrix multiplicationmatrix multiplication

wyx

sysx

tytx

wyx

1000000

1000cossin0sincos

1001001

'''

p’ = T(tx,ty) R() S(sx,sy) p

Matrix Composition

Matrices are a convenient and efficient way to Matrices are a convenient and efficient way to

represent a sequence of transformationsrepresent a sequence of transformations

• General purpose representationGeneral purpose representation

• Hardware matrix multiplyHardware matrix multiply

Matrices are a convenient and efficient way to Matrices are a convenient and efficient way to

represent a sequence of transformationsrepresent a sequence of transformations

• General purpose representationGeneral purpose representation

• Hardware matrix multiplyHardware matrix multiply

p’ = (T * (R * (S*p) ) )p’ = (T*R*S) * p

Matrix Composition

Be aware: order of transformations mattersBe aware: order of transformations matters

– Matrix multiplication is not commutativeMatrix multiplication is not commutative

Be aware: order of transformations mattersBe aware: order of transformations matters

– Matrix multiplication is not commutativeMatrix multiplication is not commutative

p’ = T * R * S * p

“Global” “Local”

Matrix Composition

What if we want to rotate What if we want to rotate andand translate? translate?

• Ex: Ex: Rotate line segment by 45 degrees about endpoint Rotate line segment by 45 degrees about endpoint aa and lengthen and lengthen

What if we want to rotate What if we want to rotate andand translate? translate?

• Ex: Ex: Rotate line segment by 45 degrees about endpoint Rotate line segment by 45 degrees about endpoint aa and lengthen and lengthen

a a

Multiplication Order – Wrong Way

Our line is defined by two endpointsOur line is defined by two endpoints

• Applying a rotation of 45 degrees, R(45), affects both pointsApplying a rotation of 45 degrees, R(45), affects both points

• We could try to translate both endpoints to return endpoint We could try to translate both endpoints to return endpoint aa to its to its original position, but by how much?original position, but by how much?

Our line is defined by two endpointsOur line is defined by two endpoints

• Applying a rotation of 45 degrees, R(45), affects both pointsApplying a rotation of 45 degrees, R(45), affects both points

• We could try to translate both endpoints to return endpoint We could try to translate both endpoints to return endpoint aa to its to its original position, but by how much?original position, but by how much?

Wrong CorrectT(-3) R(45) T(3)R(45)

aa

a

Multiplication Order - Correct

Isolate endpoint Isolate endpoint aa from rotation effects from rotation effects

• First translate line so First translate line so aa is at origin: T (-3) is at origin: T (-3)

• Then rotate line 45 degrees: R(45)Then rotate line 45 degrees: R(45)

• Then translate back so Then translate back so aa is where it was: T(3) is where it was: T(3)

Isolate endpoint Isolate endpoint aa from rotation effects from rotation effects

• First translate line so First translate line so aa is at origin: T (-3) is at origin: T (-3)

• Then rotate line 45 degrees: R(45)Then rotate line 45 degrees: R(45)

• Then translate back so Then translate back so aa is where it was: T(3) is where it was: T(3)

a

a

a

a

Will this sequence of operations work?Will this sequence of operations work?Will this sequence of operations work?Will this sequence of operations work?

Matrix Composition

1

'

'

1100

010

301

100

0)45cos()45sin(

0)45sin()45cos(

100

010

301

y

x

y

x

a

a

a

a

Matrix Composition

After correctly ordering the matricesAfter correctly ordering the matrices

Multiply matrices togetherMultiply matrices together

What results is one matrix – What results is one matrix – store it (on stack)!store it (on stack)!

Multiply this matrix by the vector of each vertexMultiply this matrix by the vector of each vertex

All vertices easily transformed with one matrix All vertices easily transformed with one matrix multiplymultiply

After correctly ordering the matricesAfter correctly ordering the matrices

Multiply matrices togetherMultiply matrices together

What results is one matrix – What results is one matrix – store it (on stack)!store it (on stack)!

Multiply this matrix by the vector of each vertexMultiply this matrix by the vector of each vertex

All vertices easily transformed with one matrix All vertices easily transformed with one matrix multiplymultiply

Overview

2D Transformations2D Transformations

• Basic 2D transformationsBasic 2D transformations

• Matrix representationMatrix representation

• Matrix compositionMatrix composition

3D Transformations3D Transformations

• Basic 3D transformationsBasic 3D transformations

• Same as 2DSame as 2D

2D Transformations2D Transformations

• Basic 2D transformationsBasic 2D transformations

• Matrix representationMatrix representation

• Matrix compositionMatrix composition

3D Transformations3D Transformations

• Basic 3D transformationsBasic 3D transformations

• Same as 2DSame as 2D

3D Transformations

Same idea as 2D transformationsSame idea as 2D transformations

• Homogeneous coordinates: (x,y,z,w) Homogeneous coordinates: (x,y,z,w)

• 4x4 transformation matrices4x4 transformation matrices

Same idea as 2D transformationsSame idea as 2D transformations

• Homogeneous coordinates: (x,y,z,w) Homogeneous coordinates: (x,y,z,w)

• 4x4 transformation matrices4x4 transformation matrices

wzyx

ponmlkjihgfedcba

wzyx

''''

Basic 3D Transformations

wzyx

wzyx

1000010000100001

'''

w

z

y

x

t

t

t

w

z

y

x

z

y

x

1000

100

010

001

'

'

'

w

z

y

x

s

s

s

w

z

y

x

z

y

x

1000

000

000

000

'

'

'

wzyx

wzyx

1000010000100001

'''

Identity Scale

Translation Mirror about Y/Z plane

Basic 3D Transformations

wzyx

wzyx

1000010000cossin00sincos

'''

Rotate around Z axis:

w

z

y

x

w

z

y

x

1000

0cos0sin

0010

0sin0cos

'

'

'

Rotate around Y axis:

wzyx

wzyx

10000cossin00sincos00001

'''

Rotate around X axis:

Reverse Rotations

Q: How do you undo a rotation of Q: How do you undo a rotation of R(R()?)?

A: Apply the inverse of the rotation… RA: Apply the inverse of the rotation… R-1-1(() = R(-) = R(-) )

How to construct R-1(How to construct R-1() = R(-) = R(-))

• Inside the rotation matrix: cos(Inside the rotation matrix: cos() = cos(-) = cos(-))

– The cosine elements of the inverse rotation matrix are unchangedThe cosine elements of the inverse rotation matrix are unchanged

• The sign of the sine elements will flipThe sign of the sine elements will flip

Therefore… RTherefore… R-1-1(() = R(-) = R(-) = R) = RTT(())

Q: How do you undo a rotation of Q: How do you undo a rotation of R(R()?)?

A: Apply the inverse of the rotation… RA: Apply the inverse of the rotation… R-1-1(() = R(-) = R(-) )

How to construct R-1(How to construct R-1() = R(-) = R(-))

• Inside the rotation matrix: cos(Inside the rotation matrix: cos() = cos(-) = cos(-))

– The cosine elements of the inverse rotation matrix are unchangedThe cosine elements of the inverse rotation matrix are unchanged

• The sign of the sine elements will flipThe sign of the sine elements will flip

Therefore… RTherefore… R-1-1(() = R(-) = R(-) = R) = RTT(())

Summary

Coordinate systemsCoordinate systems

• World vs. modeling coordinatesWorld vs. modeling coordinates

2-D and 3-D transformations2-D and 3-D transformations

• Trigonometry and geometryTrigonometry and geometry

• Matrix representationsMatrix representations

• Linear vs. affine transformationsLinear vs. affine transformations

Matrix operationsMatrix operations

• Matrix compositionMatrix composition

Coordinate systemsCoordinate systems

• World vs. modeling coordinatesWorld vs. modeling coordinates

2-D and 3-D transformations2-D and 3-D transformations

• Trigonometry and geometryTrigonometry and geometry

• Matrix representationsMatrix representations

• Linear vs. affine transformationsLinear vs. affine transformations

Matrix operationsMatrix operations

• Matrix compositionMatrix composition