Sie sind auf Seite 1von 63

Modeling

Transformations
CSE 409
Md. Tanvir Al Amin*
Lecturer, Dept. of CSE, BUET
tanviralamin@gmail.com
*Special Thanks to Tanvir Parvez, Fredo Durand, James O Brien, Tomas Lozano-Perez, Jovan Popovic

Transformation Background
What is Transformation ?

What is a Transformation
Transformation:
An operation that changes one configuration
into another

For images, shapes, etc.


A geometric transformation maps positions
that define the object to other positions
Linear transformation means the
transformation is defined by a linear
function... which is what matrices are good for.
3

What is a Transformation?
A function that maps points x to points x':
Applications: animation, deformation, viewing,
projection, real-time shadows,

Simple Transformations

Can be combined
Are these operations invertible?
Yes, except scale = 0
5

Rigid-Body / Euclidean Transforms

Preserves distances
Preserves angles

Rigid / Euclidean

Translation

Identity
Rotation

Similitudes / Similarity Transforms

Preserves angles
Similitudes
Rigid / Euclidean
Translation

Identity
Rotation

Isotropic Scaling

Linear Transformations

Similitudes
Linear
Rigid / Euclidean

Translation

Identity
Rotation

Scaling
Isotropic Scaling

Reflection
Shear
8

Linear Transformations
L(p + q) = L(p) + L(q)
L(ap) = a L(p)
Similitudes
Rigid / Euclidean
Translation

Identity
Rotation

Linear
Scaling
Isotropic Scaling

Reflection
Shear

Affine Transformations
preserves

parallel lines
Affine
Similitudes
Linear
Rigid / Euclidean

Translation

Identity
Rotation

Scaling
Isotropic Scaling

Reflection
Shear

10

Projective Transformations
preserves lines
Projective
Affine
Similitudes
Linear
Rigid / Euclidean

Translation

Identity
Rotation

Scaling
Isotropic Scaling

6.837 Fall 06 Durand


Perspective

Reflection
Shear

11

How are Transforms Represented?


x' = ax + by + c
y' = dx + ey + f
x'
=
y'

p' =

a b
d e

x
c
+
y
f

Mp + t
12

Translation in homogenous coordinates


x' = ax + by + c
y' = dx + ey + f
Cartesian formulation

x'
=
y'

p' =

a b
d e

x
c
+
y
f

Mp + t

Homogeneous formulation

x'
=
y
1

p' =

a b c
d e f
0 0 1

x
y
1

Mp
13

Homogeneous Co-ordinates
Translation, scaling and rotation are expressed

(non-homogeneously) as:
translation: P = P + T
Scale: P = S P
Rotate: P = R P

Composition is difficult to express, since

translation not expressed as a matrix multiplication


Homogeneous coordinates allow all three to be
expressed homogeneously, using multiplication by
3 matrices
W is 1 for affine transformations in graphics
14

Homogeneous Coordinates
Add an extra dimension
in 2D, we use 3 x 3 matrices
In 3D, we use 4 x 4 matrices

Each point has an extra value, w

x'
y'
z'
w'

a b
e f
=
i j
m n

p' =

c d
g h
k l
o p

Mp

x
y
z
w

15

Homogeneous Coordinates
Most of the time w = 1, and we can ignore it

x'
y'
z'
1

a
e
i
0

b c
f g
j k
0 0

d
h
l
1

x
y
z
1

If we multiply a homogeneous coordinate

by an affine matrix, w is unchanged

16

Homogeneous Co-ordinates
P2d is a projection of Ph onto the w = 1 plane
So an infinite number of points correspond to :

they constitute the whole line (tx, ty, tw)

w
w=
1

Ph(x,y,w
)
P2d(x,y,1)

y
x
17

Homogeneous Visualization

Mechanics of Rigid
Transformations
Translate
Rotate
Scale

19

Translation 2D
Y

(4,5)

(7,5)

(7,1)
Before Translation

x = x + dx
y = y + dy

x
P
y

x
P
y

Translation by (3,-4)

dx
T
dy

(10,1)
X

P P T

Homogenious Form
x 1 0 d x x
y 0 1 d * y
y


1 0 0 1 1

20

Translation 3D
x x d x
y y d y
z z d z

1 0 0 dx
0 1 0 d
y

*
0 0 1 dz


0 0 0 1

x
y

T (d x , d y , d z ) * P

x dx
yd
y

z dz

21

Scaling 2D
Y

(4,5)

Types of Scaling:
Differential ( sx != sy )
Uniform ( sx = sy )

(7,5)
(2,5/4)
X

Before Scaling

(7/2,5/4)
Scaling by (1/2, 1/4)

x s x * x
y s y * y
S

* P

Homogenious Form

x s x
y 0

1 0

sx
0

0 x x * sx
*

s y y y * s y

0
sy
0

0
0 *
1

x
y
1

22

Scaling 3D
x s x * x
y s y * y
Original

z s z * z

scale Y axis

* P

S (sx , s y , sz )

sy
0

0
sz

0
0

scale all axes

sx
0

x x * sx
y y * s
y

z z * sz

23
1 1

te d
rota

Rotation 2D
r cos
v

r
sin

or

r cos
v

r
sin

x r cos cos r sin sin


expand
y r cos sin r sin cos
x r cos
but

y r sin

x x cos y sin
y x sin y cos

al
n
i
ig

Rotation 2D
Y

Before Rotation

Rotation of 45 deg. w.r.t. origin

(4.9,7.8)
(2.1,4.9)
(5,2)

(9,2)
X

x * cos y * sin x
x * sin y * cos y
R
cos sin
sin cos

*P

x x * cos y * sin
*

y
x
*
sin

y
*
cos

Homogenious Form
x cos sin 0 x
y sin cos 0 * y


1 0

0
1 1 25

Rotation 3D
For 3D-Rotation 2
parameters are needed

Rotation about z-axis:

Angle of rotation
Axis of rotation

cos
sin

R ,k

* P

sin
cos

0 0

x
y

0 0
*

1 0 z

0 1 1

x * cos y * sin
x * sin y * cos

26

Rotation about Y-axis & X-axis


About yaxis

R , j

* P

cos
0

sin

About x-axis

0
1
0 cos

0 sin
0

0 sin
1
0
0 cos
0
0

0
0

x x * cos z * sin
y

*
z x * sin z * cos

1
1

R , i

* P

0
sin
cos
0

0
0
*
0

1

x
x

y y * cos z * sin

z y * sin z * cos

1
1

27

Rotation about Z axis


y

ZRotate()
p'

About z axis

p
x

x'
y'
z'
1

cos -sin
sin cos
0
0
0
0

0
0
1
0

0
0
0
1

x
y
z
1
28

Mirror Reflection
Y

Y
(1,1)

(-1,1)

(1,1)

(1,-1)

Reflection about X - axis


x x y y

Reflection about Y - axis


x x y y

1 0 0
M x 0 1 0
0 0 1

1 0 0
M y 0 1 0
0 0 1

29

Shearing Transformation

1 a 0
SH x 0 1 0
0 0 1

unit cube

Sheared in X
direction

1 0 0
SH y b 1 0
0 0 1

Sheared in Y
direction

SH xy

1 a 0
b 1 0
0 0 1

Sheared in both X
and Y direction

30

Shear along Z-axis

y
x
z

SH xy ( shx , sh y ) * P

1 0 shx
0 1 sh
y

0 0 1
0 0

0 x x z * shx

0 y y z * sh y
*

0 z
z

1 1
1

31

Inverse Transforms

32

Inverse Transformations
-1
(dx,dy)

Translaito n : T
Rotation
Sclaing

-1
( )

: R
: S

T(-dx,-dy)

R(- ) R

-1
(sx,sy)

T
( )

S( 1 sx , 1sy )

Mirror Ref : M M x
-1
x

M My
-1
y

33

Composing Transformations

34

How are transforms combined?


Scale then Translate
(1,1)

(2,2)

Scale(2,2)

Translate(3,1)

(5,3)
(3,1)

(0,0)

(0,0)

Use matrix multiplication: p' = T ( S p ) = TS p


TS =

1 0 3
0 1 1
0 0 1

2 0 0
0 2 0
0 0 1

2 0 3
0 2 1
0 0 1

Caution: matrix multiplication is NOT commutative!

35

Non-commutative Composition
Scale then Translate: p' = T ( S p ) = TS p
(1,1)

(2,2)

Scale(2,2)

Translate(3,1)

(5,3)
(3,1)

(0,0)

(0,0)

Translate then Scale: p' = S ( T p ) = ST p


(8,4)
(1,1)

Translate(3,1)

(4,2)
(3,1)

Scale(2,2)

(6,2)

(0,0)

36

Non-commutative Composition
Scale then Translate: p' = T ( S p ) = TS p
TS =

Translate then Scale: p' = S ( T p ) = ST p


0

0 2
0 0

0
1

0 0

ST =

0 0

1
37

Combining Translations, Rotations


Order matters!! TR is not the same as RT

(demo)
General form for rigid body transforms
We show rotation first, then translation
(commonly used to position objects) on
next slide. Slide after that works it out the
other way
38

'M10T1(TRR0)PRM
P
R
P

T
0100
R
R
T
01 RT1

xyz13211321233123113221323xyz

Rotate then Translate

39

P'M(RR0T)PRM
(010PT1T R0)R1TPT
R

132113221323 xyz1331

Translate then Rotate

40

Associativity of Matrix Multiplication


Create new affine transformations by multiplying
sequences of the above basic transformations.
q = CBAp
q = ( (CB) A) p = (C (B A))p = C (B (Ap) ) etc.
matrix multiplication is associative.
To transform just a point, better to do

q = C(B(Ap))

But to transform many points, best to do


M = CBA
then do
q = Mp
for any point p to be
rendered.
For geometric pipeline transformation, define M and
set it up with the model-view matrix and apply it to
any vertex subsequently defined to its setting.

41

Example Composite Transforms


2D Case

42

Rotation of about P(h,k): R,P


Step 1: Translate P(h,k) to origin
Step 2: Rotate w.r.t to origin
Step 3: Translate (0,0) to P(h,k0)
R,P= T(h ,k) * R* T(-h
,-k)

Q3(x+h, y
+k)
P3(h,k
)

Q(x,y)
P(h,k)

Q1(x,y
)
P1 (0,0)

Q2(x,y
)
P2 (0,0)

43

Reflection about line L, ML


Y

Step 1: Translate (0,b) to origin


Step 2: Rotate - degrees
(0,b)

Step 3: Mirror reflect about X-axis


Step 4: Rotate degrees

t
O

Step 5: Translate origin to (0,b)


ML = T(0 ,b) * R() * M x* R(-) * T(0 ,-b)
44

Rotation
How to rotate around (kx, ky, kz), a unit

vector on an arbitrary axis


Example : Rotate 30 degree around vector
2i+1j+3k
Can it be found from some rotation around x
axis, then some rotation around y axis, then z
axis ?

45

Finding the Rotation Matrix


Our previous method
Step 1,2 Perform two rotations so that a becomes aligned
with the z-axis (two rotations are necessary)
Step 3 Do the required rotation around z-axis
Step 4,5 Undo the alignment rotations to restore a to its
original direction

Trivial but you should be


careful when doing in hands
46

Step 1,2
We now study a composite transformation
AV,N = aligning a vector V with a vector N
To find the rotation matrix, we need to find

Av,k

47

AV : aligning vector V with k


Step 1 : Rotate about x - axis by
b
sin

c
cos

z
( 0, 0,

b2 c2

( 0, b,c

( a, 0,

|V|

V = aI + bJ + cK

|V|

k
b

Av =

R,i

48
x

AV : aligning vector V with k


Step 1 : Rotate about x - axis by
b
sin

c
cos

( 0, 0,

|V|)

b2 c2

a
( a, 0,

Step 2 : Rotate V about y - axis by -


a
| V |


cos( )
| V |

( 0, b,c

c
|V||V|

P( a, b, c)

sin( )

| V | a 2 b 2 c 2

Av = R-,j * R,i

49
x

AV : aligning vector V with k


AV-1 = AVT
AV,N = AN-1 * AV

a
V

AV

- ab
V
c

b
V

- ac
V
b

c
V

0
0

50

Finding the rotation matrix


Now we have done step 1,2 : AV
For step 3, we have to rotate theta angle around

z axis
Then take the inverse of step 1,2,
AV-1 = AVT

R A Rz ( ) Av
T
v

There are actually 5 rotations here. None of

which are Euler angles or or


51

Rodrigues Formula

Axis Angle Notation

a x2
1 0 0

R( a, ) cos 0 1 0 (1 cos ) a x a y
aa
0 0 1

x z

ax a y
a y2
a y az

ax az

a y a z sin
a z2

az
a
y

az

ay

ax

ax

52

The Geometry of a Rotation

53

The Geometry of a Rotation

54

The Geometry of Rotation

55

The Geometry of Rotation

Ve
cto

rF
or

So we find, the rotation vector is :


This is a vector equation, which is good
But, we need a matrix form also, to work

easily.
Rodrigues
Formula

a x2
1 0 0

R(k , ) cos 0 1 0 (1 cos ) a x a y


aa
0 0 1

x z

ax a y
a y2
a y az

ax az

a y a z sin
a z2

az
a
y

az

ay

ax

ax

Form
Matrix
56

Rodrigues Formula
Vector and Matrix forms
X x

R( x) R (k , ) X
a x2
1 0 0

R(k , ) cos 0 1 0 (1 cos ) a x a y


aa
0 0 1

x z

ax a y
a y2
a y az

0 az a y

a y a z sin a z
0 ax
a

a z2
a
0
y
x

ax az

How we find these equivalent matrix and

vector forms ?
Check next slide
57

Vector and Matrix algebra

58

Cross product in Matrix Form

59

Finding rotations from a


rotation matrix
Given, R is a pure rotation matrix
Find axis of rotation K(kx,ky,kz)

and angle theta from R


Recall rodrigues formula, it gives R
Trace ( R ) 1
cos

Check that :
2

Trace(R ) = Sum of diagonal elements of the 3x3


rotation matrix
R
60

Finding rotations from a


rotation matrix
Check that :
kz

kz
ky

0
kx

ky

kx
R RT
2 sin( )
0

1
R3,2 R2,3
2 sin( )
1
ky
( R1,3 R3,1 )
2 sin( )
1
kz
( R2,1 R1, 2 )
2 sin( )
kx

R
61

Properties of rotation matrix


The columns of rotation matrix are unit vectors

perpendicular to each other


The column vectors indicate where the unit
vectors along the principal axes are transformed
The rows of rotation matrix are unit vectors
perpendicular to each other
The row vectors indicate the vectors that are
transformed into the unit vectors along the
principal axes
The inverse of rotation matrix is its transpose
62

References
Chapter 4 and Chapter 6, Schaum's Outline

of Computer Graphics (2nd Edition) by


Zhigang Xiang, Roy A. Plastock
Chapter 5, Computer Graphics: Principles
and Practice in C (2nd Edition) by James D.
Foley, Andries van Dam, Steven K. Feiner,
John F. Hughes
Chapter 6, Fundamentals of Computer
Graphics, by Peter Shirley
63

Das könnte Ihnen auch gefallen