2D Trans
2D Trans
2D TRANSFORMATIONS
Introduction
• What is transformations?
– The geometrical changes of an object from a
current state to modified state.
• Why the transformations is needed?
– To manipulate the initially created object and to
display the modified object without having to
redraw it.
2D Transformations
• 2 ways
– Object Transformation
• Alter the coordinates descriptions an object
• Translation, rotation, scaling etc.
• Coordinate system unchanged
– Coordinate transformation
• Produce a different coordinate system
Matrix Math
• Why do we use matrix?
– More convenient organization of data.
– More efficient processing
– Enable the combination of various
concatenations
• Matrix addition and subtraction
c a c
a
= b d
b d
Basic Tranformations
• Translation
• Rotation
• Scaling
• Reflection
• Shear
Translation
• Translation is applied to an object by repositioning it along a straight-line path from one
coordinate location to another.
• New position (x’, y’) is obtained by adding the translation distance (t x,ty) (translation
vector or shift vector) to the original coordinate position (x,y).
x’ = x + tx
y’ = y + ty
• Matrix representation
x’ = x . sx
y’ = y . sy
• Example :
• P(2, 5), Sx = 0.5, Sy = 0.5
• Find P’ ?
P(2, 5)
• Example :
• P(2, 5), Sx = 2, Sy = 2
• Find P’ ?
Scaling
• Uniform scaling , Differential scaling
x’ = xf+ (x - xf) sx
y’ = yf + (y – yf) sy
x’ = x. sx + xf(1 – sx)
y’ = y. sy + yf(1 – sy)
Rotation
• Rotation is applied to an object by repositioning it along a
circular path in the xy plane.
(x, y)
x’ = x cos() - y sin()
y’ = x sin() + y cos()
2-D Rotation
x = r cos (f)
y = r sin (f)
x’ = r cos (f + )
(x’, y’) y’ = r sin (f + )
Trig Identity…
Substitute…
x’ = x cos() - y sin()
f y’ = x sin() + y cos()
2-D Rotation
• This is easy to capture in matrix form:
R=
θ r
φ (x,y)
• Rigid-body transformation. yr
• (line, Polygons, circle, ellipse)
xr x
Matrix Representation
• Point in column-vector:
x
y
1
• Scaling
x s x 0 0 x
y 0 sy 0 y
1 0 0 1 1
Order of operations
So, it does matter. Let’s look at an example:
1. Translate 1. Rotate
2. Rotate 2. Translate
Other transformations
Reflection:
x-axis y-axis
1 0 0 1 0 0
0 1 0 0 1 0
0 0 1 0 0 1
Other transformations
Reflection:
origin line x=y
1 0 0 0 1 0
0 1 0 1 0 0
0 0 1
0 0 1
Other transformations
Shear:
x-direction y-direction
1 shx 0 1 0 0
0 1 0 sh
y 1 0
0 0 1 0 0 1
Shear
• Converted to a parallelogram
y (1,1) y
(0,1)
1 sh x 0 (2,1) (3,1)
0 1 0
(0,0) (1,0) x
(0,0) (1,0)
x
0 0 1
x’ = x + shx · y, y’ = y
(Shx=2)
(Shx=1/2, yref=-1)
x’ = x + shx · (y-yref), y’ = y
cgvr.korea.ac.kr
Shear
• Transformed to a shifted parallelogram
(X = Xref)
(0,3/2) (1,2)
1 0 0 y y
sh 1 sh y x ref (1,1)
y (0,1)
0 (0,1/2) (1,1)
0 1
x x
(0,0) (1,0) (-1,0)
x’ = x, y’ = shy · (x-xref) + y
(Shy=1/2, xref=-1)
cgvr.korea.ac.kr
Reflection
• Reflection with respect to the axis
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
y 1 y y
1 1’ 1’
2 3 2 3 3’ 2 3’ 2
x x 3 x
2’ 3’ 1
1’ 2
Reflection
Reflection with respect to a Line
y
0 1 0
1 0 0
x
0 0 1
y y 1
y
2 3
x 2 3 x
x
’ ’
1
’
Using Transformations (1)
• In 3D, many cubes make a city.
Using Transformations (2)
• The snowflake exhibits symmetries.
• We design a single motif and draw the whole
shape using appropriate reflections, rotations,
and translations of the motif.
use it 12 times
Using Transformations (3)
• A designer may want to view an object from
different vantage points.
• Positioning and reorienting a camera can be
carried out through the use of 3D affine
transformations.
Interactive Computer Graphics Chapter 9 - 29