Computer Graphics
2D Transformations
1
Transformation
Transform every point on an object according to certain rule.
Q (x’, y’)
P (x,y)
T
Initial Object
Transformed Object
x x’ The point Q is the image of P under the transformation
y y’ T.
Geometric Transformation
• Why do we need geometric
transformations in CG?
– As a viewing aid
– As a modeling tool
– As an image manipulation tool
Translation
(55,60)
(20,35)
(45,30)
(65,30)
x x tx
(10,5) (30,5)
y y t y
The vector (tx, ty) is called the offset vector.
Rotation About the Origin
y
(x’,y’)
(x’,y’)
(x,y)
(x,y)
o x
x x cos y sin
y x sin y cos
The above 2D rotation is actually a rotation about the z-axis (0,0,z) by
an angle .
Rotation About a Pivot Point
(x’,y’) (x,y)
(xp , yp)
Pivot Point
•Pivot point is the point of rotation
•Pivot point need not necessarily be on the object
Rotation About a Pivot Point
STEP-1: Translate the pivot point to the origin
(x,y)
(x1, y1)
(xp , yp)
x1 x x p
y1 y y p
Rotation About a Pivot Point
STEP-2: Rotate about the origin
(x2, y2) (x1, y1)
x 2 x1 cos y1sin
y 2 x1 sin y1 cos
Rotation About a Pivot Point
STEP-3: Translate the pivot point to original position
(x’, y’)
(x2, y2)
(xp, yp)
x x 2 x p
y y 2 y p
Scaling About the Origin
(x’,y’)
(x,y)
x x. s x
(x,y)
(x’,y’)
y y. s y
Uniform Non-Uniform
( sx , s y 0) The parameters sx, sy are called scale factors.
Uniform: sx s y Non-Uniform: sx s y
Scaling About a Fixed Point
• Translate the fixed point to origin
(x,y) • Scale with respect to the origin
•Translate the fixed point to its original
(x’,y’) position.
(xf , yf )
x ( x x f ).s x x f
y ( y y f ).s y y f
Reflections
y
Reflection about y Initial
Object
x = x
Reflection about
origin
Reflection about x
x = x
y = y
y = y
Shear
x x hx y
y y
•A shear transformation in the x-direction (along x)
shifts the points in the x-direction proportional
to the y-coordinate.
•The y-coordinate of each point is unaffected.
Shear
• Two common shearing transformations are those that
shift coordinate x values and those that shift y values.
• An x-direction shear relative to the x axis is produced with
the transformation matrix (shx=2)
y y
x’ = x + shx · y, (0,1) (1,1)
(2,1) (3,1)
y’ = 1y shx 0 (0,0) (1,0) x x
0 1 0
(0,0) (1,0)
0 0 1
• An y-direction shear relative to the y axis is produced with
the transformation matrix
1 0 0
y’ = y + shy · x, sh
x’ = x y 1 0
0 0 1
Matrix Representation
• Represent a 2D Transformation by a Matrix
a b
c d
• Apply the Transformation to a Point
x ax by x a b x
y cx dy y c d y
Transformation
Point
Matrix
2×2 Matrices
2D Scaling
x sx x x sx 0 x
y sy y y 0 sy y
2×2 Matrices
2D Rotation
x cos x sin y x cos sin x
y sin cos y
y sin x cos y
2D Shearing
x x shx y x 1 shx x
y shy 1 y
y shy x y
2×2 Matrices
• Reflection
2D Mirror over Y axis
x x x 1 0 x
y 0 1 y
y y
2D Mirror over x,y axis
x x x 1 0 x
y y y 0 1 y
Matrix Representations
x x t x
Translation y y t
y
Rotation [Origin]
x cos sin x
y sin cos y
x sx 0 x
Scaling [Origin] y 0 s y
y
Matrix Representations
x 1 0 x
Reflection about x y 0 1 y
x 1 0 x
Reflection about y
y 0 1 y
Reflection about x 1 0 x
the Origin y 0 1 y
Matrix Representations
Shear along x x 1 h x
y 0 1 y
x 1 0 x
Shear along y
y h 1 y
Homogeneous Coordinates
To obtain square matrices an additional row was added to the matrix and an
additional coordinate, the w-coordinate, was added to the vector for a point.
In this way a point in 2D space is expressed in three-dimensional
homogeneous coordinates.
This technique of representing a point in a space whose dimension is one
greater than that of the point is called homogeneous representation. It
provides a consistent, uniform way of handling affine transformations.
An affine
transformatio
n is a linear
mapping
method that
preserves
parallel lines,
points, and
planes. It can
involve
translation,
rotation, or
uniform [6]-22
Homogeneous Coordinates
• A standard technique for expanding each two-
dimensional coordinate position representation (x, y) to
( xh , yh , h)
three-element representation ,called Homogeneous
Coordinates, where homogeneous h is a nonzero value
such that
xh yh
x , y
h h
• For geometric transformation, we can choose the
homogeneous parameter h to be any nonzero value. Thus
there are an infinite number of equivalent homogeneous
representations for each coordinate point (x, y) .
• A convenient choice is simply to set h=1, so each two-
dimensional position is then represented with
homogeneous coordinate (x,y,1).
• Expressing positions in homogenous coordinates allows
us to represent all geometric transformation equations
as matrix multiplications, which is the standard method
used in graphics systems.
• Two dimensional coordinate positions are represented
with three-elements column vectors, and two-
dimensional transformation operations are expressed
as 3X3 matrices.
• Homogeneous coordinate representation of 2D Translation
x 1 0 tx x
x x tx y 0 1 ty y
y y ty
1 0 0 1 1
• This translation operation can be written in the abbreviated
form
P ' T (t x , t y ) P
• Homogeneous coordinate representation of 2D Rotation
x cos sin 0 x
y sin cos 0 y
1 0 0 1 1
This rotation operation can be written in the
abbreviated form
'
P R( ) P
• Homogeneous coordinate representation of 2D Scaling
x sx 0 0 x
y 0 sy 0 y
1 0 0 1 1
This scaling operation can be written in the
abbreviated form
'
P S ( sx, sy ) P
• Properties of homogeneous coordinate 2D
transformation.
• (1) Translation and rotation have additive properties.
T (t x , t y ) T (t h , tl ) T (t x t h , t y tl )
R (1 ) R ( 2 ) R(1 2 )
• (2) Scaling transformation has multiplicative properties.
S ( sx, st ) S ( sh, sl ) S ( sx sh, st sl )
Homogeneous Coordinates
Basic Transformations
x 1 0 t x x
Translation y 0 1 t y
P’=TP y
1 0 0 1 1
x cos sin 0 x
Rotation [O] y sin cos 0 y
P’=RP
1 0 0 1 1
x sx 0 0 x
Scaling [O] y 0 s 0 y
P’=SP y
1 0 0 1 1 [6]-29
Inverse of Transformations
If, x x then, x x
y [T ] y y [T ] 1 y
1 1 1 1
1
Examples: T (t x , t y ) T ( t x , t y )
R 1 ( ) R( )
1 1
S ( s x , s y ) S ,
1
s s
x y
H x 1 (h) H x ( h) [6]-30
Transformation Matrices
Additional Properties:
T (t x , t y )T (u x , u y ) T (t x u x , t y u y )
R (1 ) R ( 2 ) R (1 2 )
R ( ) 1
S ( s x , s y ) S ( wx , wy ) S ( s x wx , s y wy )
Composite Transformations
Transformation T followed by x x
Transformation Q followed by y [ R ][Q ][T ] y
Transformation R:
1 1
Example: (Scaling with respect to a fixed point)
x 1 0 x f sx 0 0 1 0 x f x
y 0 1
0 0 1 y f y
yf 0 sy
1 0 0 1 0 0 1 0 0 1 1
Order of Transformations
Order of Transformations
In composite transformations, the order of
transformations is very important.
Rotation followed by Translation:
Translation followed by Rotation:
Matrix Composition
• Transformations can be combined by matrix multiplication
x 1 0 tx cos θ - sinθ 0 sx 0 0 x
y 0 1 ty sinθ cosθ 0 0 sy 0 y
w 0 0 1 0 0 1 0 0 1 w
p T(tx, ty) R( ) S(sx, sy) p
Matrix multiplication is associative
p (T (R (S p))) p (T R S) p
Matrix Composition
• Rotate by around arbitrary point (a,b)
M T(a, b) R(θ ) T(-a,-b) (a,b)
• Scale by sx, sy around arbitrary point (a,b)
M T(a, b) S(sx, sy) T(-a,-b) (a,b)
Pivot-Point Rotation
(xr,yr (xr,yr (xr,yr (xr,yr
) ) ) )
Translate Rotate Re-Translate
T xr , yr R T xr , yr Rxr , yr ,
1 0 x r cos sin 0 1 0 x r cos sin x r (1 cos ) y r sin
0 1 y sin cos 0 0 1 y sin cos y r (1 cos ) x r sin
r r
0 0 1 0 0 1 0 0 1 0 0 1
Rotation about the point (2,3) by +90
P’= T(x,y) R(theta)T(-x,-y) P= T(-2,-3) R(90)T(+2,+3) P
P’=
P’==