You are on page 1of 31

1

Computer Graphics
Chapter 6
2D Transformations
-2
R
M
Transform every point on an object according to certain rule.
Initial bject
Transformed bject
! "#\$y%
& "#'\$ y'%
# #'
y y'
Transformation
T
T(e point & is t(e image of ! under t(e
transformation T.
-)
R
M
+
+
x x t
y y t
x
y
"*+\$,% ")+\$,%
"2+\$),%
",,\$6+%
"6,\$)+%
"-,\$)+%
Translation
T(e vector "t
#
\$ t
y
% is called t(e offset vector.
--
R
M
Translation (OpenGL)
.pecifying a 2/-Translation0
glTranslatef(tx, ty, 0.0);
"T(e 1 component is set to + for 2/ translation%.
-,
R
M
"#\$y%
"#'\$y'%

+
x x y
y x y
cos sin
sin cos

o
"#\$y%
"#'\$y'%
#
y
Rotation About the Origin
T(e above 2/ rotation is actually a rotation about t(e
1-a#is "+\$+\$*% by an angle .
-6
R
M
Rotation About the Origin
.pecifying a 2/-Rotation about t(e origin0
glRotatef(theta, 0.0, 0.0, 1.0);
theta0 2ngle of rotation in degrees.
T(e above function defines a rotation about t(e 1-a#is "+\$+\$*%.
-3
R
M
"#
p
\$ y
p
%
"#\$y%
"#'\$y'%
!ivot !oint
4
!ivot point is t(e point of rotation
4
!ivot point need not necessarily be on t(e object
Rotation About a Pivot Point
-5
R
M
"#
p
\$ y
p
%
p
p
y y y
x x x

*
*
"#\$y%
"#*\$ y*%
STEP-1: Translate the pivot point to the origin
Rotation About a Pivot Point
-6
R
M

cos * sin * 2
sin * cos * 2
y x y
y x x
+

"#*\$ y*%
STEP-2: Rotate about the origin
"#2\$ y2%
Rotation About a Pivot Point
-*+
R
M
p
p
y y y
x x x
+

2
2
STEP-3: Translate the pivot point to original position
"#2\$ y2%
"#
p
\$ y
p
%
"#'\$ y'%
Rotation About a Pivot Point
-**
R
M
+
+ +
x x x y y x
y x x y y y
p p p
p p p
" % cos " % sin
" % sin " % cos

.pecifying a 2/-Rotation about a pivot point "#p\$yp%0
glTranslatef(xp, yp, 0);
glRotatef(theta, 0, 0, 1.0);
glTranslatef(-xp, -yp, 0);
7ote t(e pen89 specification of t(e se:uence of transformations in t(e
reverse order ;
Rotation About a Pivot Point
-*2
R
M

x x s
y y s
x
y
.
.
s s
x y

<niform 7on-<niform
s s
x y

" \$ % s s
x y
> +
"#\$y%
"#'\$y'%
"#\$y%
"#'\$y'%
Scaling About the Origin
T(e parameters s
#
\$ s
y
are called scale factors.
-*)
R
M
.pecifying a 2/-.caling =it( respect to t(e origin0
glScalef(sx, sy, 1.0);
sx, sy0 .cale factors along #\$ y.
>or proper scaling sx, sy must be positive.
>or 2/ scaling\$ t(e t(ird scale factor must be set to *.+.
Scaling About the Origin
-*-
R
M
"#
f
\$ y
f
%
f y f
f x f
y s y y y
x s x x x
+

%. "
%. "
"#\$y%
"#'\$y'%
4
Translate t(e fi#ed point to origin
4
.cale =it( respect to t(e origin
4
Translate t(e fi#ed point to its original
position.
Scaling About a Fie! Point
-*,
R
M
Reflections
Initial
bject
y ? y
x
y
origin
x ? x
y ? y
x ? x
-*6
R
M
Reflections
Reflection about #0 glScalef(1, -1, 1);
Reflection about y0 glScalef(-1, 1, 1);
Reflection about origin0 glScalef(-1, -1, 1);
-*3
R
M
Shear
+

x x h y
y y
x
4
2 s(ear transformation in t(e #-direction "along #%
s(ifts t(e points in t(e #-direction proportional
to t(e y-coordinate.
4
T(e y-coordinate of eac( point is unaffected.
-*5
R
M

1
]
1

1
]
1
+

1
]
1

1
]
1

1
]
1

1
]
1

1
]
1

1
]
1

1
]
1
x
y
x
y
t
t
x
y
x
y
x
y
s
s
x
y
x
y
x
y
cos sin
sin cos

+
+
Translation
Rotation [rigin]
.caling [rigin]
"atri Representations
-*6
R
M
1
]
1

1
]
1

1
]
1

1
]
1

1
]
1

1
]
1

1
]
1

1
]
1

1
]
1

y
x
y
x
y
x
y
x
y
x
y
x
* +
+ *
* +
+ *
* +
+ *
"atri Representations
t(e rigin
-2+
R
M
1
]
1

1
]
1

1
]
1

1
]
1

1
]
1

1
]
1

y
x
h y
x
y
x h
y
x
*
+ *
* +
*
.(ear along #
"atri Representations
.(ear along y
-2*
R
M
#omogeneous Coor!inates
To obtain s:uare matrices an additional ro= =as added to t(e matri# and an
additional coordinate\$ t(e w-coordinate\$ =as added to t(e vector for a point.
In t(is =ay a point in 2/ space is e#pressed in t(ree-dimensional
(omogeneous coordinates.
T(is tec(ni:ue of representing a point in a space =(ose dimension is one
greater t(an t(at of t(e point is called (omogeneous representation. It
provides a consistent\$ uniform =ay of (andling affine transformations.
-22
R
M
@artesian Aomogeneous
+ %\$ \$ \$ " \$
+ %\$ \$ \$ " % \$ "

,
_

c c b a
c
b
c
a
h h yh xh y x
B#amples0 ",\$ 5% "*,\$ 2-\$ )%
"#\$ y% "#\$ y\$ *%
#omogeneous Coor!inates
4
If =e use (omogeneous coordinates\$ t(e geometric
transformations given above can be represented using
only a matri# pre-multiplication.
4
2 composite transformation can t(en be represented
by a product of t(e corresponding matrices.
-2)
R
M

1
]
1
1
1

1
]
1
1
1

1
]
1
1
1

1
]
1
1
1

1
]
1
1
1

1
]
1
1
1

1
]
1
1
1

1
]
1
1
1

1
]
1
1
1
x
y
t
t
x
y
x
y
x
y
x
y
s
s
x
y
x
y
x
y
*
* +
+ *
+ + * *
*
+
+
+ + * *
*
+ +
+ +
+ + * *
cos sin
sin cos

Translation
P=TP
Rotation []
P=RP
.caling []
P=SP
Basic Transformations
#omogeneous Coor!inates
-2-
R
M
1
1
1
]
1

1
1
1
]
1

*
] [
*
y
x
T y
x
If\$
1
1
1
]
1

1
1
1
]
1

*
] [
*
*
y
x
T y
x
t(en\$
% " % "
*
\$
*
% \$ "
% " % "
% \$ " % \$ "
*
*
*
*
h H h H
s s
S s s S
R R
t t T t t T
x x
y x
y x
y x y x

,
_

B#amples0
\$nverse of Transformations
-2,
R
M
% \$ " % \$ " % \$ "
* % "
% " % " % "
% \$ " % \$ " % \$ "
2 * 2 *
y y x x y x y x
y y x x y x y x
w s w s S w w S s s S
R
R R R
u t u t T u u T t t T

+
+ +

2dditional !roperties0
Transformation "atrices
-26
R
M
Transformation T followe b!
Transformation " followe b!
Transformation R:
1
1
1
]
1

1
1
1
]
1

*
] ][ ][ [
*
y
x
T Q R y
x
E#ample: \$Scaling with respect to a fi#e point%

1
]
1
1
1

1
]
1
1
1

1
]
1
1
1

1
]
1
1
1

1
]
1
1
1
x
y
x
y
s
s
x
y
x
y
f
f
x
y
f
f
*
* +
+ *
+ + *
+ +
+ +
+ + *
* +
+ *
+ + * *
Composite Transformations
rder of Transformations
-23
R
M
In composite transformations\$ t(e order of
transformations is very important.
Or!er of Transformations
Rotation follo=ed by Translation0
Translation follo=ed by Rotation0
-25
R
M
pen89 postmultiplies t(e current matri#
=it( t(e ne= transformation matri#
Or!er of Transformations (OpenGL)
glMatrixMode(G!M"#\$%&\$');
glTranslatef(tx, ty, 0);
glRotatef(theta, 0, 0, 1.0);
gl%ertex(f(x,y);
Rotation followe b! Translation &&
@urrent Matri#
' ( )
' T )
' T ) ' R )
' T ) ' R ) P
-26
R
M
9ine 2ngle /istance 2rea
Translation Ces Ces Ces Ces
Rotation Ces Ces Ces Ces
.caling Ces 7o 7o 7o
Reflection Ces Ces Ces Ces
.(ear Ces 7o 7o Ces
Preserve *ttributes
General Properties
-)+
R
M
2 general invertible\$ linear\$ transformation.
+ +
+ +

x a x b y c
y a x b y c
a b a b
* * *
2 2 2
* 2 2 *
+ " %
Affine Transformation
Transformation Matri#0
1
1
1
]
1

* + +
2 2 2
* * *
c b a
c b a
-)*
R
M
4
!roduct of affine transformations is affine.
4
2ffine transformations preserve linearity of segments.
4
2ffine transformations preserve parallelism bet=een
lines.
4
2ffine transformations are invertible.
Affine Transformation% Properties