CST 304 - Computer Graphics: 2D Transformations
CST 304 - Computer Graphics: 2D Transformations
Module-2 Part-2
2D TRANSFORMATIONS
• Basic
Transformations
• Matrix representations, Homogeneous coordinates
• Composite Transformations
2D Transformations
• Geometric Transformation
– The geometrical change of an object from a current state to
modified state.
– To manipulate the initially created object and to alter and display
the modified object without having to redraw it.
Eg : designing, animation
– Two types:-
– Object Transformation
• Changes orientation, size and shape of object
• Alter the coordinates descriptions an object
• Translation, rotation, scaling, shear, reflection, etc.
• Coordinate system unchanged
– Coordinate transformation
• Produce a different coordinate system
Matrix Representation
• Column-vector representation for a point.
• Pre-multiplication of the transformation – it appears
before the point to be transformed in the equation.
A B x Ax By
C
D y Cx Dy
• Advantages of Matrix
– More convenient organization of data
– More efficient processing
– Enable the combination of various concatenations
2D Translation
A translation moves all points in an
object along the same straight-line
path from original position (x, y) to
new position (x’, y’)
The translation distance pair (tx , ty),
P ?
is called translation or shift vector. (8,6)
Translation equations are: 2)(
x' = x + tx ty = 4
P
y' = y + ty tx = 6
(2, 2)
or in matrix form:
P' = P + T
x’ x tx
y’ = y + t
y
2D Translation
A translation is a rigid body transformation that moves objects
without deformation. That is every point on the object is translated
by the same amount.
• Line segment - add translation vector to each of line end points
and redrawing line between new end point positions.
• Polygons - add translation vector to coordinate position of each
vertex and regenerate polygon using new set of vertex coordinates
and current attribute settings
• Circle or Ellipse - add translation vector to center coordinate and
redraw it in new location
• Curves (splines) - add translation vector to coordinate positions of
object and reconstruct curve paths using new set of coordinates
2D Rotation
• Rotation - a rigid body transformation
that repositions all points in an object
along a circular path in the xy plane
centered at the pivot point.
• A rotation angle and position (xr ,yr) P’
of rotation point or pivot point about
which object is to be rotated is
specified.
• can be clockwise (-ve) or P
counterclockwise (+ve).
• Rotation is about a rotation axis
perpendicular to xy plane and passes
through the pivot point.
2D Rotation
• First, assume that pivot is at the origin (0,0).
• Review Trigonometry
=> cos = x/r , sin = y/r
x = r cos , y = r sin P’(x’, y’)
y’ = x sin + y cos
2D Rotation
• Rotation equations:
x’ = x cos – y sin
y’ = x sin + y cos
• or in matrix form:
P’(x’, y’)
P' = R • P
x ' cos sin x
y ' sin cos y
y’
P(x,y)
• Rotation matrix
cos sin r y
R
sin cos x
x’
• For a rotation matrix transpose
is got by simply changing sign
of sine terms
2D Rotation
y
Rotation in angle about a
x, y P Pr R P Pr
xr , yr x cos
R
sin
sin cos
2D Rotation
Example - Find the transformed point, P’, caused by rotating
P= (5, 1) about the origin through an angle of 90.
P’
•
Scaling
If the scale factors are in between 0
and 1 the points will be moved
P’
closer to the origin the object will
be smaller.
• Example :
•P(2, 5), Sx = 0.5, Sy = 0.5
P(2, 5)
•Find P’ ?
•If the scale factors are larger than 1
the points will be moved away P’
• Differential scaling.
- scale factors are different, Sx Sy
- change in size and shape
- Example : square rectangle
P(1, 3), Sx = 2, Sy = 5 , P’ ? P(1, 3)
• Unit Scaling
- scale factors are both 1, Sx = Sy = 1
- size and shape unchanged
2D Scaling
Scaling about a fixed point x f , y f
Sx
x' x f ( x x f ) s x
Sy y' y f ( y y f )s y
or
y
x x s x x f 1 s x
y y s y y f 1 s y
x f , yf
x
P P S P f 1 - S
Note: the additive terms xf (1-Sx) and yf (1-Sy) are constants for
all points in the object
Combining Transformations
General transformation of a point:
P' = M1 • P + M2
P' and P - column matrix (2 x 1) of new and original coordinates
M1 - 2 x 2 matrix for scaling and rotation
M2 - column matrix (2 x 1) for translation
• For scaling or rotation, we set M2 as the additive identity.
• For translation, we set M1 is the multiplicative identity.
• To combine multiple transformations, we must explicitly compute
each transformed point. It is better to use the same matrix operation
all the time, so have to combine multiplication and addition into a
single matrix representation by expanding 2x2 to 3x3 matrices
• Cartesian coordinate (x, y) replaced by homogeneous coordinate
triplet (xh ,yh, h) equal to (x.h, y.h, h) where x = xh/ h, y = yh / h
• Homogeneous representation allows to represent all geometric
transformation equations as concatenated matrix multiplications
Homogeneous Coordinates
y y
w
x
x
• Let point (x, y) in 2D be represented by point (x, y, 1) in the new
space. Scaling our new point by any value a puts us somewhere
along a particular line: (ax, ay, a).
• A point in 2D can be represented in many ways in the new space.
• (2, 4) (8, 16, 4) or (6, 12, 3) or (2, 4, 1) or etc.
• We can always map back to the original 2D point by dividing by the
last coordinate (15, 6, 3) (5, 2)
• Since all the points along each line can be mapped back to the same
point in 2D this coordinate system –> homogeneous coordinates
Homogeneous Transform Advantages
x cos sin 0 x
2D y sin cos 0 y , P R P
Rotation
1 0 0 1 1
x S x 0 0 x
y 0 S 0 y , P S S , S P
2D
Scaling y x y
1 0 0 1 1
19
Homogeneous Coordinates
Inverse transformations:
1 0 t x cos sin 0 1 S x 0 0
T1 0 1 t y , R 1 sin cos 0 , S1 0 1 S y 0
0 0 1 0 0 1 0 0 1
Composite Transformations:
P M 2 M1 P M 2 M 1 P M P
Composite Translation:
P T t2 x , t2 y T t1x , t1 y P T t2 x , t 2 y T t1x , t1 y P
1 0 t2 x 1 0 t1x 1 0 t1x t 2 x
0 1 t 0 1 t 0 1 t t
2y 1y 1y 2y
0 0 1 0 0 1 0 0 1
R 2 R 1 R 1 2
P R 1 2 P
Composite Scaling:
S2 x 0 0 S1x 0 0 S1x S 2 x 0 0
0 S2 y 0 0 S1 y 0 0 S1 y S 2 y 0
0 0 1 0 0 1 0 0 1
0 0 1 0 0 1 0 0 1
3. Translate pivot point back
to original position cos sin xr 1 cos yr sin
sin cos yr 1 cos xr sin
22
0 0 1
General Fixed Point 2D Scaling
1 0 x f S x 0 0 1 0 x f S x 0 x f 1 S x
0 1 y 0 S 0 0 1 y 0 S y 1 S
f y f y f y
0 0 1 0 0 1 0 0 1 0 0 1
T(xf , yf ) . S (sx , sy T(- xf , - yf ) = S ( xf , yf , sx , sy )
2D Scaling Steps
1. Translate object such that fixed point moves to origin
2. Scale object about origin
April 2010 23
3. Translate fixed point back to original position
2D Directional Scaling
x
S2
R 1 S S1 , S 2 R
0 0 1
S1 S1 1
2D Directional Scaling Steps: x S2 2 x
1. Rotate (scaling direction
align 45O
with the coordinate axes)
2. Scale with respect to origin
3. Rotate (scaling direction is y y
returned to original position)
April 2010 24
R(–) • S(scale) • R()
2D Reflections
Reflection- Transformation that produces a mirror image. Rotation about
reflection axis by 1800 . Reflection axis can be in xy plane or perpendicular to
xy plane. Rotation path will be in a perpendicular plane.
The inverse of a reflection corresponds to its transpose
y y y
x x
1 0 0 1 0 0 1 0 0
0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1
Reflection about line y = 0 Reflection about line x = 0 Reflection about origin
25
(x - axis) (y - axis) (xy - axis)
2D Reflections
3
2
yx y x
2
1
1
3
2 1 1 3
0 1 0 0 1 0
1 0 0 1 0 0
0 0 1 0 0 1
Reflection about line y = x Reflection about line y = - x
Clockwise Rotation by 450 Clockwise Rotation by 450
Reflection about X-axis Reflection about Y-axis
Counter - Clockwise Rotation by 450
April 2010 Counter - Clockwise Rotation by 45
26 0
2D Shear
• A shear is a transformation that distorts the shape of an object such
that the transformed shape appears as if the object was composed of
internal layers that had been caused to slide over each other.
• Two common shearing transformations are those that shift coordinate
x values and those that shift coordinate y values y
Equations 1
x x shx ( y yref )
1 x
y y yref = -1
Matrix form y
y 0 1 0 y 1 2 3 x
1 0 0 1 1
yref = -1
shx = ½, yref =28-1
2D Shear
• Y-direction shear relative to y-axis (x=0)
shifts the points in the y-direction proportional
to the x-coordinate. But x-coordinate of points y
are unaffected.
1
Eg. Square converted to a parallelogram
Equations 1 x
x x Initial object
y y shy x y
3
Matrix form 2
x 1 0 0 x 1
y shy 1 0 y 1 x
1 0 0 1 1 shy = 2
29
2D Shear
• Y-direction shear relative to reference lines (x=x ref )
Eg. Square converted to vertically shifted parallelogram y
Equations
x x 1
y y shy ( x xref )
xref = -1 1 x
Matrix form
y
x 1 0 0 x 2
y shx 1 shy xref y
1
1 0 0 1 1
xref = -1 1 x
shy = ½, xref = -1 30
Transformations between 2D Coordinate Systems
y
y’
x’
y0
x0 x
M xy , xy R ( ) T ( x0 , y0 )
32
Order of Transformations
y y
x x
Object first translated in the x Object first rotated 90º and then
direction and then rotated 90º translated in the x direction
33
Composite Transformation
• We can represent any sequence of transformations
as a single matrix.
–No special cases when transforming a point – matrix • vector.
–Composite transformations – matrix • matrix.
• Composite transformations:
Rotate about an arbitrary point – translate, rotate, translate
Scale about an arbitrary point – translate, scale, translate
Change coordinate systems – translate, rotate, scale