CENG 477 Introduction to Computer...

53
CENG 477 Introduction to Computer Graphics Modeling Transformations

Transcript of CENG 477 Introduction to Computer...

Page 1: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

CENG 477Introduction to Computer Graphics

Modeling Transformations

Page 2: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Modeling Transformations• Model coordinates to World coordinates:

World coordinates:All shapes with theirabsolute coordinates and sizes.

zworld

xworld

yworldModel coordinates:All shapes with theirlocal coordinates and sizes.

CENG 477 – Computer Graphics 2

Page 3: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Basic Geometric Transformations• Used for modeling, animation as well as viewing• What to transform?

– We typically transform the vertices (points) and vectors describing the shape (such as the surface normal)

• This works due to the linearity of transformations• Some, but not all, transformations may preserve attributes like

sizes, angles, ratios of the shape

CENG 477 – Computer Graphics 3

Page 4: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Translation• Simply move the object to a relative position

TPP

PTP

+=

y'x'

=tt

=yx

=

t+y=y't+x=x'

y

x

yx

'

' ⎥⎦

⎤⎢⎣

⎡⎥⎦

⎤⎢⎣

⎡⎥⎦

⎤⎢⎣

P

P'

CENG 477 – Computer Graphics 4

Page 5: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation• A rotation is defined by a rotation axis and a rotation angle• For 2D rotation, the parameters are rotation angle (θ) and the

rotation point (xr, yr)• We reposition the object in a circular path around the rotation

point (pivot point)

a

xr

yr

CENG 477 – Computer Graphics 5

Page 6: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation• When (xr, yr)=(0,0) we have:

P

P'

θφθφθφ

θφθφθφ

cossinsincos)sin(sinsincoscos)cos(

rrryrrrx

+=+=ʹ

−=+=ʹ

φ

φ

sincosryrx

=

=The original coordinates are:

θθ

θθ

cossinsincosyxyyxx

+=ʹ

−=ʹSubstituting them in the first equation we get:

In the matrix form we have: PRP ⋅=ʹ

⎥⎦

⎤⎢⎣

⎡ −=

θθ

θθ

cossinsincos

R

CENG 477 – Computer Graphics 6

Page 7: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation• Rotation around an arbitrary point (xr, yr)

• These equations can be written as matrix operations (we will see when we discuss homogeneous coordinates)

P

P'

θθ

θθ

cos)(sin)(sin)(cos)(

rrr

rrr

yyxxyyyyxxxx

−+−+=ʹ

−−−+=ʹ

(xr,yr)

CENG 477 – Computer Graphics 7

Page 8: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Scaling• Changes the size of an object • Input: scaling factors (sx, sy)

PSP

S

' ⋅

⎥⎦

⎤⎢⎣

=

ss

=

ys=y'xs=x'

y

x

yx

00

PP'

non-uniform vs.uniform scaling

CENG 477 – Computer Graphics 8

Page 9: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Homogenous Coordinates• Translation is additive, rotation and scaling is multiplicative

(and additive if you rotate around an arbitrary point or scale around a fixed point)

• Goal: Make all transformations as matrix operations• Solution: Add a third dimension

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

1yx

=hyhxh

=hyx

=Phy=y

hx=x h

hhh

CENG 477 – Computer Graphics 9

Page 10: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Homogenous Coordinates• In HC, each point now becomes a line• The entire line represents the same point• The original (non-homogeneous) point resides on the w=1

plane

x

y

w

w = 1p1

p2

CENG 477 – Computer Graphics 10

All points along this linein HC represent the samepoint, p1

Page 11: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Transformations in HC

• Translation:

• Rotation:

• Scaling:

( ) ( )⎥⎥⎥

⎢⎢⎢

1001001

where y

x

yxyx' t

t=t,tTPt,tT=P

( ) ( )⎥⎥⎥

⎢⎢⎢

⎡ −

1000cossin0sincos

where θθθθ

=θRPθR=P'

( ) ( )⎥⎥⎥

⎢⎢⎢

⋅ʹ

1000000

where y

x

yxyx ss

=s,sSPs,sS=P

CENG 477 – Computer Graphics 11

Page 12: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Transforming Vectors• Vectors can be rotated and scaled• But translating a vector does not change it! Why?

– A vector is a difference between two points– These two points translate the same way– So the vector remains the same

• Mathematically this can be achieved by setting the last coordinate of a vector to 0 (the last coordinate of points should be 1)

CENG 477 – Computer Graphics 12

2D point 𝑥𝑦 in HC is equal to

𝑥𝑦1

2D vector 𝑥𝑦 in HC is equal to

𝑥𝑦0

Page 13: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Composite Transformations• Often, objects are transformed multiple times• Such transformations can be combined into a single composite

transformation• E.g. Application of a sequence of transformations to a point:

PMPMMP 12

⋅=

⋅⋅=ʹ

CENG 477 – Computer Graphics 13

Page 14: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Composite Transformations• Composition of the same types of transformations is simple• E.g. translation:

( ) ( ) ( )yyxxyy

xx

y

x

y

x

yxyx t+t,t+tT=tttt

=tt

tt

=t,tTt,tT 212121

21

1

1

2

2

1122

1001001

1001001

1001001

⎥⎥⎥

⎢⎢⎢

+

+

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

PTTPTTP⋅⋅=

⋅⋅=ʹ

)},(),({

}),({),(

1122

1122

yxyx

yxyx

tttttttt

CENG 477 – Computer Graphics 14

Page 15: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

( ) ( ) ( )yyxxyy

xx

y

x

y

x

yxyx ss,ss=ssss

=ss

ss

=s,ss,s 212121

21

1

1

2

2

1122

1000000

1000000

1000000

⋅⋅

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

⋅ SSS

( ) ( )

( )φ+θ=φ+θφ+θφ+θφ+θ

=φθ+φθφθ+φθφθφθφθφθ

=θθθθ

=φθ

R

RR

⎥⎥⎥

⎢⎢⎢

⎡ −

⎥⎥⎥

⎢⎢⎢

−−−

⎥⎥⎥

⎢⎢⎢

⎡ −

⎥⎥⎥

⎢⎢⎢

⎡ −

1000)cos()sin(0)sin()cos(

1000coscossinsinsincoscossin0cossinsincossinsincoscos

1000cossin0sincos

1000cossin0sincos

ϕϕ

ϕϕ

Composite Transformations• Rotation and scaling are similar:

CENG 477 – Computer Graphics 15

Page 16: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around a Pivot Point• Step 1: Translate the object so that the pivot point moves to

the origin

( )rr y,x −−T

( )rr y,xM −−= T1

CENG 477 – Computer Graphics 16

Page 17: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around a Pivot Point• Step 2: Rotate around origin

( )θR

( )θR=2M

CENG 477 – Computer Graphics 17

Page 18: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around a Pivot Point• Step 3: Translate the object so that the pivot point is back to its

original position

( )rr y,xT

( )rr y,xM T=3

CENG 477 – Computer Graphics 18

Page 19: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around a Pivot Point• The composite transformation is equal to their successive

application:

( ) ( ) ( )rrrr y,xy,xMMMM −−== TRT θ123

CENG 477 – Computer Graphics 19

Page 20: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Scaling w.r.t. a Fixed Point• The idea is the same:

– Translate to origin– Scale– Translate back

( ) ( ) ( )

( )( )

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

−−⋅⋅

1001010

1001001

1000000

1001001

yfy

xfx

f

f

y

x

f

f

ffyxff

syssxs

=yx

ss

yx

=y,xs,sy,x TST

( )ff y,x −−T

( )yx s,sS

( )ff y,xT

CENG 477 – Computer Graphics 20

Page 21: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Order of matrix compositions• Matrix composition is not commutative. So, be careful when

applying a sequence of transformations.

Pivot

21

Rotation and translation

Pivot

12

Translation and rotation

CENG 477 – Computer Graphics 21

Page 22: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Other Transformations• Reflection: special case of scaling

⎥⎥⎥

⎢⎢⎢

100

010

001

⎥⎥⎥

⎢⎢⎢

⎡−

100

010

001

⎥⎥⎥

⎢⎢⎢

100

010

001

CENG 477 – Computer Graphics 22

Page 23: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Other Transformations• Shear: Deform the shape like shifted slices (or deck of cards).

Can be in x or y direction

(1,1)(3,1)

(2,1)

x ' x shx y y ' y

1 shx 00 1 00 0 1

(0,1)

CENG 477 – Computer Graphics 23

Page 24: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

3D Transformations• Similar to 2D but with an extra z component• We assume a right handed coordinate system• With homogeneous coordinates we have 4 dimensions • Basic transformations: Translation, rotation, scaling

x

y

z

z

x

y

y

z

x

Equivalent ways of thinking about a right-handed CS

CENG 477 – Computer Graphics 24

Page 25: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Translation• Move the object by some offset:

z

y

x

z

y

x

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥

⎢⎢⎢⎢

ʹ

ʹ

ʹ

11000100010001

1zyx

ttt

zyx

z

y

x

PTP ⋅=ʹ

P

CENG 477 – Computer Graphics 25

Page 26: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation• Rotation around the coordinate axes

• Positive angles represent counter-clockwise (CCW) rotation when looking along the positive half towards origin

z

x

y

z

x

y

z

x

y

z

x

y

z

x

y

z

x

y

x-axis y-axis z-axis

CENG 477 – Computer Graphics 26

Page 27: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around Major Axes• Around x:

• Around y:

• Around z:

⎥⎥⎥⎥

⎢⎢⎢⎢

−=

10000cossin00sincos00001

)(θθ

θθθxR PRP ⋅=ʹ )(θx

⎥⎥⎥⎥

⎢⎢⎢⎢

⎡ −

=

1000010000cossin00sincos

)(θθ

θθ

θzR PRP ⋅=ʹ )(θz

⎥⎥⎥⎥

⎢⎢⎢⎢

−=

10000cos0sin00100sin0cos

)(θθ

θθ

θyR PRP ⋅=ʹ )(θy

CENG 477 – Computer Graphics 27

Page 28: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around a Parallel Axis• Rotating an object around a line parallel to one of the axes:

Translate to a major axis, rotate, translate back• E.g. rotate around a line parallel to x-axis:

z

y

x

z

y

x

z

y

x

z

y

x

Translate Rotate Translate back

PTRTP ⋅−−⋅⋅=ʹ ),,0()(),,0( ppxpp zyzy θ

(yp, zp)

CENG 477 – Computer Graphics 28

Page 29: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around an Arbitrary Axis• Step 1: Translate the object so that the rotation axis passes

though the origin• Step 2: Rotate the object so that the rotation axis is aligned

with one of the major axes• Step 3: Make the specified rotation• Step 4: Reverse the axis rotation• Step 5: Translate back

z

y

x

CENG 477 – Computer Graphics 29

Page 30: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around an Arbitrary Axis

CENG 477 – Computer Graphics 30

Page 31: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around an Arbitrary Axis• First determine the axis of rotation:

• u is the unit vector along v:

),,( 12121212 zzyyxx −−−=−= PPv

),,( cba==vvu

CENG 477 – Computer Graphics 31

Page 32: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around an Arbitrary Axis• Next translate P1 to origin:

⎥⎥⎥⎥

⎢⎢⎢⎢

=

1000100010001

1

1

1

zyx

T

CENG 477 – Computer Graphics 32

Page 33: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around an Arbitrary Axis• Then align u with one of the major axis (x, y, or z)• This is a two-step process:

– Rotate around x to bring u onto xz plane (CCW)– Rotate around y to align the result with the z-axis (CW)

z

x

u

y

α

z

xu

y

β

We need cosine and sine of angles α and ß

CENG 477 – Computer Graphics 33

Page 34: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around an Arbitrary Axis• We need cosine and sine of angles α and ß:

z

x

uu'

uz

y

αux

uyu = ux + uy + uz = ux + u’

22z whereucos cbddc

+==ʹ

=u

α

db

=uyusinα

⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢

−=

1000

00

000001

)(

dc

db

db

dc

x αR

CENG 477 – Computer Graphics 34

Page 35: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around an Arbitrary Axis• We need cosine and sine of angles α and ß:

z

x

y

ux

222

2222

coscba

cbuu zy

++

+=

+=

22zy uu +

β u

222sin

cbaaux

++==

⎥⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢⎢

++

+

++−

++++

+

=

1000

00

0010

00

)(

222

22

222

222222

22

cbacb

cbaa

cbaa

cbacb

y βR

CENG 477 – Computer Graphics 35

Note that 𝑎& + 𝑏& + 𝑐& = 1

-

+

Page 36: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Rotation Around an Arbitrary Axis• Putting it all together:

),,()()()()()(),,()( 111111 zyxzyx xyzyx −−−⋅⋅⋅⋅−⋅−⋅= TRRRRRTR αβθβαθ

This is the actual desiredrotation. Other terms arefor alignment and undoingthe alignment

CENG 477 – Computer Graphics 36

-+

Page 37: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Alternative Method• Assume we want to rotate around the unit vector u:• We create an orthonormal basis (ONB) uvw:

CENG 477 – Computer Graphics 37

z

x

u

y

z

x

u

y

v

w

1) To find v, set the smallestcomponent of u (in anabsolute sense) to zero andswap the other two whilenegating one:

E.g. if u = (a, b, c) with c being the smallest absolutevalue then v = (-b, a, 0)

Note that we are just finding one of the infinitely many solutions

This corresponds to projectingthe vector to the nearest major planeand rotating it 90° along the axisperpendicular to that plane

2) w = u x v

3) Normalize v and w

Page 38: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Alternative Method• Now rotate uvw such that it aligns with xyz: call this

transform M• Rotate around x (u is now x)• Undo the initial rotation: call this M-1

• Finding M-1 (rotating xyz to uvw) is trivial:

CENG 477 – Computer Graphics 38

⎥⎥⎥⎥

⎢⎢⎢⎢

=−

1000000

1

zzz

yyy

xxx

wvuwvuwvu

M

Verify that this matrix transforms x to u, y to v, and z to w

• How to transform x = [1 0 0 0]T

such that it turns into [ux uy uz 0]T

• Similar for the y and z axis

Page 39: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Alternative Method• Finding M is also trivial as M-1 is an orthonormal matrix (all

rows and columns are orthogonal unit vectors)• For such matrices, inverse is equal to transpose:

CENG 477 – Computer Graphics 39

⎥⎥⎥⎥

⎢⎢⎢⎢

=

1000000

zyx

zyx

zyx

wwwvvvuuu

M

Page 40: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Alternative Method• The final rotation transform is:

• We assumed that the origin of uvw is the same as the origin of xyz

• Otherwise, we should account for this difference:

CENG 477 – Computer Graphics 40

𝑀,-𝑅/(𝜃)𝑀

𝑇,-𝑀,-𝑅/(𝜃)𝑀𝑇

Translate the originof uvw to xyz

Undo thetranslation

Page 41: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Scaling• Change the coordinates of the object by scaling factors

x 'y 'z '1

sx 0 0 00 s y 0 00 0 sz 00 0 0 1

xyz1

P' S P

z

y

x

z

y

x

PSP ⋅=ʹ

P

CENG 477 – Computer Graphics 41

Page 42: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Scaling w.r.t. a Fixed Point• Translate to origin, scale, translate back

z

y

x

z

y x

z

y

x

z

y

x

Translate Scale Translate back

PTSTP ⋅−−−⋅⋅=ʹ ),,(),,( ffffff zyxzyx

CENG 477 – Computer Graphics 42

Page 43: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Reflection• Reflection over the major planes:

z

y

x

z

y

x

z

y

x

⎥⎥⎥⎥

⎢⎢⎢⎢

⎡−

1000010000100001

⎥⎥⎥⎥

⎢⎢⎢⎢

1000010000100001

⎥⎥⎥⎥

⎢⎢⎢⎢

1000010000100001

How about reflection over an arbitrary plane?

CENG 477 – Computer Graphics 43

Page 44: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Transforming Normals• When we transform an object, what happens to its normals?• Do they get transformed by the same matrix or does it require

a different one?

x

y

1

1 x

y

1

3

⎥⎥⎥

⎢⎢⎢

=

100010003

S

Scale by:

𝒏 =1/√21/√20

𝒏 =3/√21/√20

CENG 477 – Computer Graphics 44

Page 45: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Transforming Normals• After the transformation the normal is no longer perpendicular

to the object• Also it is not a unit vector anymore

x

y

1

1 x

y

1

3

⎥⎥⎥

⎢⎢⎢

=

100010003

S

Scale by:

𝒏 =1/√21/√20

𝒏 =3/√21/√20

CENG 477 – Computer Graphics 45

Page 46: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Transforming Normals• Rotation and translation has no problems• But, since all transformations are combined into a single

matrix M, we should consider the general case.

• We must have n.(b-a) = n.v = 0 and this relationship should be preserved after the transformation

n

a

bv

CENG 477 – Computer Graphics 46

Page 47: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Transforming Normals• That is n.v = 0 and n'.v' = 0 where v' = Mv and n' = Zn• Z is the matrix we are looking for• How to compute Z?

n

a

bv

CENG 477 – Computer Graphics 47

Page 48: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

Transforming Normals• n.v = nTv = 0• n'.v' = n'Tv' = n'T Mv = nTZTMv = 0• If ZTM = I (identity) the relationship will be preserved• So Z = (M-1)T

• Note that this is equal to (MT)-1 as (M-1)T= (MT)-1 for a square (n by n) matrix M

n

a

bv

CENG 477 – Computer Graphics 48

Page 49: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

A Word on Notation• Until now, we performed transformations by multiplying our

points from the right:

• Another notation is to multiply from the left:

CENG 477 – Computer Graphics 49

𝑥9𝑦9𝑧91

=

𝑎 𝑏 𝑐 𝑑𝑒 𝑓 𝑔 ℎ𝑖 𝑗 𝑘 𝑙0 0 0 1

𝑥𝑦𝑧1

𝑥9 𝑦9 𝑧9 1 = 𝑥 𝑦 𝑧 1

𝑎 𝑏 𝑐 𝑑𝑒 𝑓 𝑔 ℎ𝑖 𝑗 𝑘 𝑙0 0 0 1

D

Note that in this caseeverything is transposed

Page 50: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

A Word on Terminology• Imagine a 2D rotation matrix such as:

• Transforming an object by this matrix will not change its shape• If we also add translation:

• The shape will remain intact

CENG 477 – Computer Graphics 50

cos(𝜃) −sin(𝜃) 0sin(𝜃) cos(𝜃) 00 0 1

cos(𝜃) −sin(𝜃) 𝑡/sin(𝜃) cos(𝜃) 𝑡M0 0 1

Page 51: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

A Word on Terminology• In general, an arbitrary sequence of rotation and translation

matrices will have the following form:

• Such transformations are called rigid-body transformations• A shape may be rotated and translated by its form is not altered

in any way

CENG 477 – Computer Graphics 51

𝑟-- 𝑟-& 𝑡/𝑟&- 𝑟&& 𝑡M0 0 1

Page 52: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

A Word on Terminology• Imagine also adding scaling• The matrix will now look like:

• Such transformations will not necessarily preserve lengths and angles, but parallel lines will remain parallel

CENG 477 – Computer Graphics 52

𝑎 𝑏 𝑡/𝑐 𝑑 𝑡M0 0 1

where a, b, c, d contain the effect ofrotation and scaling combined

Original Rotation Rotation and scaling

Page 53: CENG 477 Introduction to Computer Graphicssaksagan.ceng.metu.edu.tr/courses/ceng477/files/pdf/05_A... · 2019. 11. 1. · Modeling Transformations • Model coordinates to World coordinates:

A Word on Terminology• Such transformations are called affine transformations• An arbitrary sequence of rotation, translation, scaling, and

shearing will produce an affine transformation• Note that we still have some degrees of freedom left in the last

row of our matrix:

• By using this we can create projective transformations in which parallel lines may no longer be parallel

CENG 477 – Computer Graphics 53

𝑎 𝑏 𝑡/𝑐 𝑑 𝑡M0 0 1