52
March 1, 2009 Dr. Muhammed Al-Mulhem 1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem Dr. Muhammed Al-Mulhem March 1, 2009 March 1, 2009

March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

Embed Size (px)

Citation preview

Page 1: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 1

ICS 415Computer Graphics

Transformation

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem

March 1, 2009March 1, 2009

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem

March 1, 2009March 1, 2009

Page 2: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 2

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

Page 3: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 3

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

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

Page 4: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 4

2D Modeling Transformations

ScaleRotate

Translate

ScaleTranslate

x

y

World Coordinates

Modeling Coordinates

Page 5: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 5

2D Modeling Transformations

x

y

Let’s lookat this indetail…

Page 6: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 6

2D Modeling Transformations

x

y

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

Page 7: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 7

2D Modeling Transformations

x

y

Scale .3, .3Rotate -90

Translate 5, 3

Page 8: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 8

2D Modeling Transformations

x

y

Scale .3, .3Rotate -90

Translate 5, 3

Page 9: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 9

2D Modeling Transformations

x

y

Scale .3, .3Rotate -90

Translate 5, 3

World Coordinates

Page 10: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 10

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

Page 11: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 11

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

Page 12: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 12

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

Page 13: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 13

2-D Rotation

(x, y)

(x’, y’)

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

Rotation equation

Page 14: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 14

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

Trigonometric Identities…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’)

r

r

Original coordinate of the point in polar coordinate

Page 15: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 15

2-D Rotation

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

y

x

y

x

cossin

sincos

'

'

Page 16: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 16

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

Page 17: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 17

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

Page 18: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 18

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’)

Page 19: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 19

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

Page 20: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 20

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’)

Page 21: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 21

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

Page 22: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 22

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

Page 23: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 23

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

'

'

Page 24: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 24

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!

Page 25: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 25

2x2 Matrices

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

What types of transformations can be represented with a What types of transformations can be represented with a 2x2 matrix?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

'

'

Page 26: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 26

2x2 Matrices

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

What types of transformations can be represented with a What types of transformations can be represented with a 2x2 matrix?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

'

'

Page 27: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 27

2x2 Matrices

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

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

2D Mirror about Y axis?

yyxx

''

yx

yx

1001

''

2D Mirror over (0,0)?

yyxx

''

yx

yx

1001

''

Page 28: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 28

2x2 Matrices

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

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

2D Translation?

y

x

tyy

txx

'

'

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

NO!

Page 29: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 29

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:

• 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

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:

• 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

y

x

dc

ba

y

x

'

'

Page 30: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 30

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

'

'

Page 31: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 31

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 make graphics operations Homogeneous coordinates make graphics operations muchmuch easier easier

Homogeneous coordinates make graphics operations Homogeneous coordinates make graphics operations muchmuch easier easier

Page 32: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 32

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

'

'

Page 33: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 33

Translation

Example of translationExample of translationExample 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

Page 34: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 34

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

Page 35: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 35

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

Page 36: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 36

Affine TransformationsAffine 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

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

wyx

fedcba

wyx

100''

Page 37: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 37

Projective TransformationsProjective 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

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

wyx

ihgfedcba

wyx

'''

Page 38: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 38

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

Page 39: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 39

Matrix Composition

Transformations can be combined by matrix Transformations can be combined by matrix multiplicationmultiplication

Transformations can be combined by matrix Transformations can be combined by matrix multiplicationmultiplication

wyx

sysx

tytx

wyx

1000000

1000cossin0sincos

1001001

'''

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

Page 40: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 40

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

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

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

Page 41: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 41

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”

Page 42: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 42

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 aRotate line segment by 45 degrees about endpoint a

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 aRotate line segment by 45 degrees about endpoint a

a a

Page 43: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 43

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 a to its We could try to translate both endpoints to return endpoint a 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 a to its We could try to translate both endpoints to return endpoint a 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

Page 44: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 44

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

Page 45: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 45

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

Page 46: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 46

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

Page 47: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 47

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

Page 48: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 48

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

''''

Page 49: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 49

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

Page 50: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 50

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:

Page 51: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 51

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 RHow 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 RHow 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(())

Page 52: March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Transformation Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009

March 1, 2009 Dr. Muhammed Al-Mulhem 52

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