Transformations Transformations
TransformationsTransformations
Geometric Transformations
� Transformation τ is one-to-one and onto mapping of
Rn to itself (in general)
� Affine transformation – τ (V) = AV+b
A – matrix
b – scalar
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
3
b – scalar
� In CG Geometric Transformations are, for the most
part, affine transformations with geometric meaning
� Note: transformation has meaning only for vectors ⇒for point P, τ (P) is a transformation of vector from the
origin to P
Transformations
� Transforming an object = transforming all its points
� For a polygonal model = transforming its vertices
Is it true for any transformation?
Why is it true for us?
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
4
Applications
� Viewing
� Modeling
� Animation
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
5
� Animation
� Image manipulation
Scaling
� V = (vx,vy) – vector in XY plane
� Scaling operator S with parameters (sx,sy):
( )( ) ( )yyxx
sssvsvVS yx ,
, =
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
6
( ) ( )yyxx svsvVS ,=
Scaling� Matrix form:
( )( ) ( ) ( )yyxx
y
x
yx
sssvsv
s
svvVS yx ,
0
0,
, =
=
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
7
� Independent in x and y
Non uniform scaling is allowed
� What is the meaning of scaling by zero?
Rotation
� Polar form:
W
y
V
x
r
αθ
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
8
� Polar form:
V=(vx,vy)=(r cosα, r sinα)
� Rotating V anti-clockwise by θ to W:
)cossinsincos
,sinsincoscos(
))sin(),cos((
),(
θαθαθαθα
θαθα
rr
rr
rr
yw
xwW
+−=
++=
=
Rotation
� Matrix form:
−=
−=
θθθθ
θθθθ
αα
cossin
sincos
cossin
sincos)sin,cos(
V
rrW
)cossinsincos
,sinsincoscos(
θαθαθαθα
rr
rrW
+−=
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
9
� Rotation operator R with parameter θ at the origin:
−=
θθθθ
θ
cossin
sincosR
Rotation Properties
� Rθ is orthogonal
� R-θ - rotation by -θ is
( ) ( )TRR θθ =−1
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
10
� R - rotation by -θ is
( ) 1
cossin
sincos),()(
−− =
−= θθ
θθθθ
RvvVR yx
Translation
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
11
� Translation operator T with parameters (tx,ty):
� Can you express T in a matrix form?
( )( ) ( )yyxx
tttvtvVT yx ++= ,
,
Translation - Homogeneous
Coordinates� To represent T in matrix form
– introduce homogeneous
coordinates:
� Conversion (projection) from
( ) ( )1,,,, h
y
h
x
h
w
h
y
h
x
h vvvvvV ==
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
12
� Conversion (projection) from
homogeneous space to
Euclidean:
� In homogeneous
coordinates:
(2, 2, 1) = (4, 4, 2) = (1, 1, 0.5)
==
h
w
h
y
h
w
h
xyx
v
v
v
vvvV ,),(
Translation
� Using homogeneous coordinates, the translation
operator may be expressed as:
001
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
13
)1,,(
1
010
001
)1,,()(),(
yyxx
yx
yx
htt
tvtv
tt
vvVTyx
++=
=
Matrix Form
�Why did we insist on using a Matrix form to
represent the transformations?
Hint: How would you go about transforming
an object of m vertices through a sequence of
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
14
an object of m vertices through a sequence of
n transformations?
Transformation Composition
� What operation rotates XY by θ around P = (px,py) ?
� Answer:
Translate P to origin
Rotate around origin by θ
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
15
Rotate around origin by θ
Translate back
Transformation Composition
=−−
0010sincos001
),(),( ppppTRT yxyx
θθθθ
θ
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
16
−− 1
010
100
0cossin-
1
010
yxyx pppp
θθ
Transformations Quiz
� What do these
transformations do?
� And these homogeneous
ones?
−
01
10
01
5.000
010
001
1-00
010
001
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
17
� How can one mirror a planar
object through an arbitrary
line in XY?
� Can one rotate a planar
object in the XY plane via
mirroring?
−
−
10
1
11
01
10
01
10
a
Rotate by Shear
� Shear
� Rotation by 0 ≤ θ ≤ π/2 ≡ composition of 3 shears
1011sincos zxθθ
1
01,
10
1,
10
11,
11
01
a
a
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
18
.1
1
10
1
1
1
10
1
1
01
10
1
cossin-
sincos
+
+++=
+=
=
yzy
xxyzzxy
z
y
xxy
z
y
x
θθθθ
Rotate by Shear (cont.)
� Solve for x, y, z :
cos θ = 1+xy = yz+1
sin θ = −y = z+xyz+x
.1
1
cossin-
sincos
+
+++=
yzy
xxyzzxy
θθθθ
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
19
� Solution:
y = −sin θx = z = −tan(θ / 2)
QuestionQuestion: When is rotation-using-three-shears useful?
QuestionQuestion: Can we derive a rotation via two shears?
Rotate by Shear (cont.)
� What does the composition of
the following two scaled shears
do?
=
θθθθ sincos0secsin1
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
20
� Why use it?
� Is it convenient?
� What happens when θ → π/2 ?
=
−
θθθθ
θθ
θθ
cossin-
sincos
1tan
0sec
cos0
sin1
Rotation Approximation
� For small angles can approximate:
x’=x cosθ − y sinθ ≅ x − yθy’=x sinθ + y cosθ ≅ xθ + y
Since cosθ → 1 and sinθ → θ as θ → 0 (Taylor expansion of sin/cos)
� Example (steps of θ ):
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
21
� When is this rotation approximation useful?
� App. rotation matrix
� Matrix has to be orthogonal & normalized
Rotation Approximation
−
=1
1
θθθAR
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
22
� Matrix has to be orthogonal & normalized
� ARθ is orthogonal
� ARθ not normalized
�Normalize
2
1
1
1 θθ
θθ +=
−= cAR
cc
cc
3D Transformations
� All 2D transformations extend to 3D
� In homogeneous coordinates:
Scale Translate Rotate (around z axis)
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
23
�� QuestionQuestion: What is ? ?
−
=
=
=
1000
0100
00cossin
00sincos
1
0100
0010
0001
1000
000
000
000
),,(),,( θθθθ
θz
zyx
ttt
z
y
x
sssR
ttt
Ts
s
s
S zyxzyx
θxR
θyR transformations
3D Transformations
� Questions (commutativity):
Scaling: Is S1S2 = S2S1?
Translation: Is T1T2 = T2T1?
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
24
Rotation: Is R1R2 = R2R1?
Example: Arbitrary Rotation
YZ
W
V
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
25
� Problem:
Given two orthonormal coordinate systems XYZ and UVW ,
Find a transformation from one to the other.
X
U
Arbitrary Rotation
� Answer: Transformation matrix R
whose rows are U, V, W:
� Proof:
uuu
=
zyx
zyx
zyx
www
vvv
uuu
R
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
26
� Similarly R(Y) = V & R(Z) = W
U
uuu
www
vvv
uuu
XR
zyx
zyx
zyx
zyx
=
=
=
),,(
)0,0,1()(
� Inverse (=transpose) transformation, R-1, provides
mapping from UVW to XYZ
� E.g.
Arbitrary Rotation (cont.)
wvu
wvu
uuuUR yyy
xxx
zyx
=− ),,()(1
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
27
� Comment: Used for mapping between XY plane and
arbitrary plane (why is this useful!?)
X
uuu
wvu
wvuuuuUR
zyx
zzz
yyyzyx
=
=
++=
=
)0,0,1(
)0,0,(
),,()(
222
� Lemma: Affine image of line segment is line segment
between image of its end points
� Proof:
Given affine transformation A & line segment S(t) = P1t + P2(1-t)
Transformation of Objects
))1(())(( 21 tPtPAtSA −+=
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
28
� Is an affine image of a plane, a plane?
� Conclusion: polyhedron (polygon) is affinely transformed
by transforming its vertices
)()1()(
))1(()(
))1(())((
21
21
21
PAtPtA
tPAtPA
tPtPAtSA
−+=
−+=
−+=
Viewing Transformations� Question: How can we view (draw)
3D objects on a 2D screen?
� Answer:
Project the transformed object along Z
axis onto XY plane - and from there to
screen (space)
Canonical projection:ObjectObjectspacespace
ViewViewspacespace
ScreenScreenspacespace
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
29
Canonical projection:
1000
0000
0010
0001
� In practice “ignore” the z axis – simply use the x and y
coordinates for screen coordinates
z
ObjectObjectspacespace
ScreenScreenspacespace
Parallel Projection
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
30
Parallel Projection
� Projectors are all parallel
Orthographic: Projectors perpendicular to projection plane
Axonometric: Rotation + translation + orthographic projection
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
31
Parallel Projection� Projectors are all parallel
Oblique projection: Projectors not necessarily perpendicular to
projection plane
transformations
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
32
� When can the oblique projection used?
What is Wrong in this Korean Picture?
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
33
Perspective Projection
� Viewing is from point at a
finite distance
� Without loss of generality:
Viewpoint at origin
projection
plane
X
p2 p3
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
34
Viewing plane is z=d
� Given P=(x, y, z), triangle
similarity gives:
dz
yy
dz
xx
d
y
z
y
d
x
z
xpp
pp
/ and
/ and ==⇒==
center of
projection
projectors
x2p
x1p= x3
p
z = d
p1= (x1, y1, z1)
Z
� In matrix notation with homogeneous coordinates:
Perspective Projection (cont’d)
.,,,
0000
/1100
0010
0001
)1,,,()1,,,(
=
=d
zzyx
dzyxzyxP
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
35
� In Euclidean coordinates:
� P not injective & singular: det(P)=0
0000
).,,(,/
,//
,/
,/
dyxddz
y
dz
x
dz
z
dz
y
dz
xpp=
=
transformations
Perspective Projection (cont’d)� What is (if any) the difference between:
Moving the projection plane
camtrans
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
36
Moving the viewpoint (center of projection)?
Examples of Perspective projection
Perspective could be defined with
one, two or three focal points:
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
37
Examples of Perspective projection
The same model in
Orthographic view Perspective view
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
38
Examples of Perspective projection
The same model with
Small perspective warp Large perspective warp
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
39
More than Three Points’ Perspective!?
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
40
Perspective Warp� P not invertible – can not get depth (order) back.
� Idea:
Warp the viewing frustum (and the entire world)
Then use parallel projection
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
41
Question: Why
do we require
the depth
information?
Perspective Warp
� Matrix formulation
−
−=
− d
z
d
dzyx
dd
dzyx ,
)(,,
100
0010
0001
)1,,,(α
α
α
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
42
� This matrix maps the x and y coordinates much like
the perspective map in slide 34.
−
−−
− dd
d
ddd
000
α
αα
α
( )( )
−−
=zd
zd
dz
y
dz
xzyx ppp α
α2
,/
,/
),,(
Perspective Warp
� What does α = 0 mean? α = d ?
� What is the effect of changing d, d >α ?
� The perspective warp preserves relative depth (third
coordinate). For what depth domain? Prove it!
( )( )
−−
=zd
zd
dz
y
dz
xzyx ppp α
α2
,/
,/
),,(
camtrans
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
43
coordinate). For what depth domain? Prove it!
� The perspective warp preserves planes (prove it!)
� Plane Ax + By + Cz + D = 0 is warped to (prove it!):
Aαdxp + Bαdyp + D(α − d)zp + Cαd2 + Dd2 = 0
� What does warp do to other objects? Spheres?
Perspective Warp� We will show that the six faces of the
view frustum are mapped to six faces
of a box
� Plane z = d (d ≠ 0), A=B=0, C=1, D=-d and the plane is
warped to -d(α -d)zp+α d2 - d3 = 0 or zp = d
Ax + By + Cz + D = 0 ⇒ Aαdxp + Bαdyp + D(α − d)zp + Cαd2 + Dd2 = 0
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
44
p p
� Plane z = α (α ≠ 0), A=B=0, C=1, D=-α and the plane is
warped to -α(α -d)zp+α d2 -α d2 = 0 or zp = 0
� Plane x = ±z, A=1, B=0, C= ±1, D=0 and the plane is
warped to αdxp ± α d2 = 0 or xp = ± d
� Plane y = ±z, A=0, B=1, C= ±1, D=0 and the plane is
warped to αdyp ± α d2 = 0 or yp = ± d
What is the difference between
O = M No & O = N M o, N new transform
Another Transformations Quiz� What does each transformation preserve?
linesparallel
linesdistance angles normals convexity
Conics
(spherity)
scaling
rotation
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
46
� A map that preserves angles is called conformal.
� A map that preserves distances is called an Isometry.
translation
shear
perspective
Everything is a matter of Perspective
Sidewalk Chalk PaintingsSidewalk Chalk Paintings
Transformations Transformations -- Center for Graphics and Geometric Computing, Center for Graphics and Geometric Computing,
TechnionTechnion
47
Julian Julian BeeverBeever