Documente Academic
Documente Profesional
Documente Cultură
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
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
Preserves distances
Preserves angles
Rigid / Euclidean
Translation
Identity
Rotation
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
Reflection
Shear
11
p' =
a b
d e
x
c
+
y
f
Mp + t
12
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
Homogeneous Coordinates
Add an extra dimension
in 2D, we use 3 x 3 matrices
In 3D, we use 4 x 4 matrices
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
16
Homogeneous Co-ordinates
P2d is a projection of Ph onto the w = 1 plane
So an infinite number of points correspond to :
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
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
y r sin
x x cos y sin
y x sin y cos
al
n
i
ig
Rotation 2D
Y
Before Rotation
(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
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
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
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)
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
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
(2,2)
Scale(2,2)
Translate(3,1)
(5,3)
(3,1)
(0,0)
(0,0)
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
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(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 =
0 2
0 0
0
1
0 0
ST =
0 0
1
37
(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
39
P'M(RR0T)PRM
(010PT1T R0)R1TPT
R
132113221323 xyz1331
40
q = C(B(Ap))
41
42
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
t
O
Rotation
How to rotate around (kx, ky, kz), a unit
45
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
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
c
cos
( 0, 0,
|V|)
b2 c2
a
( a, 0,
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
a
V
AV
- ab
V
c
b
V
- ac
V
b
c
V
0
0
50
z axis
Then take the inverse of step 1,2,
AV-1 = AVT
R A Rz ( ) Av
T
v
Rodrigues Formula
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
53
54
55
Ve
cto
rF
or
easily.
Rodrigues
Formula
a x2
1 0 0
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
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
vector forms ?
Check next slide
57
58
59
Check that :
2
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
References
Chapter 4 and Chapter 6, Schaum's Outline