2D Geometric Transformations Guide
2D Geometric Transformations Guide
Transformations
Dr.Chougule N.K.
1
Geometric transformation
2
Content
Need of Transformations
Basic 2D geometric transformations
2D translation
2D rotation
2D scaling
2D Homogeneous Coordinates
2D Composite transformations
Examples on 2D Transformations
3
Types of Transformations
There are two ways of understanding a transformation-
Geometric Transformation and Co-ordinate Transformations
An Object (Geometric) Transformation alters the coordinates
of each point according to some rule, leaving the underlying
coordinate system unchanged
i.e.Moving object relative to a stationary co-ordinate system
{.4, 2}
{1,1}
Another example to animate flying of aeroplane, we require aeroplane as object and sky
as background. In geometric transformation, we can simulate this by moving aeroplane
while keeping the sky background fixed.
Types of Transformations continued….
{1,1}
{1,1}
We can simulate aeroplane by keeping aeroplane fixed while moving background i.e.
sky.
etc...
use it 12 times
Need of Transformations continued…..
2. A designer may want to observe object from different view points, by
rotating /moving the object
{.4, 2}
{1,1}
Another example to animate flying of aeroplane, we require aeroplane as object and sky
as background. In geometric transformation, we can simulate this by moving aeroplane
while keeping the sky background fixed.
Types of Transformations continued….
{1,1}
{1,1}
We can simulate aeroplane by keeping aeroplane fixed while moving background i.e.
sky.
P = {2, 2}
e.g: P is the point {2, 2}, Tr is a transform that
scales by a factor of 2. Then T(P) = 2({2, 2}) = {4,4}
Scale by 2
P’ = {4, 4}
Elementary Geometric Transformations
Transformations are usually combinations of Three elementary
transformations:
1: Translation
2: Scaling
3: Rotation
1.Translation Transformation ( T )
A translation moves an object into a different position in a scene
If P’- New position of point P, P-Original position and
T- Translation matrix then, Mathematically P’ =P+T
x’ = x + tx and y’ = y + ty ,
tx & ty are translation factors along X and Y direction
Translate by T
q P
Rotate by q
Original points
Transformed points
18
Rotation - derivation
PX R cos ( ) [1]
Py R sin ( ) [2]
20
3. Scaling Transformation ( S )
A scaling changes the size of an object with two scale factors, Sx and Sy (if
Sx = Sy, then we have a uniform scale)
If a scaling factor greater than one indicates an expansion of
length and less than one indicates a compression of length
If Sx or Sy < 0, the image is reflected across the x or y axis.
Sx, Sy
Scale by
Sx, Sy
Original points Transformed points
X' Y'
4 2
(2,1) 2
P' x p' y 2 1
2 0
= [4 2 ]
0 2
Ch 5 - 23 CS 380
Differential Scaling -Distortion
X 2,
Y 0.5
P' x p' y 2 1
2 0
= [4 0.5 ]
0 0 .5
3. Scaling Transformation ( S )
Example 3-Scale the rectangle A(-1,-1), B(1,-1), C(1,1) and D(-1,1) by
2 units in x and y direction about origin
3. Scaling Transformation ( S )
If Sx < 0, the image is reflected across the Y axis
C’ D’
B’ A’
1 -1
-1 0 -1 -1
0 1 -1 1
1 1
3. Scaling Transformation ( S )
If SY < 0, the image is reflected across the X axis
A’ B’
D’ C’
-1 1
1 0 1 1
0 -1 1 -1
-1 -1
3. Scaling Transformation ( S )
If Sx or Sy < 0, the image is reflected across the x or y axis
B’ A’
C’ D’
1 1
-1 0 -1 1
0 -1 -1 -1
1 -1
Differential Scaling
• If the scale factors are the same, Sx = Sy
uniform scaling P’
• Only change in size (as previous example)
For Scaling-
Sx 0 0
P’=P. Where M1 is Scaling matrix and M2 =0.
0 Sy 0
Thus all 2D points are represented by three numbers (x,y,1) instead of two. This co-
ordinate system is called homogeneous co-ordinate system. 30
Homogeneous Representation
Translation
1 0 0
0 1 0
x' y' 1 x y 1
P' P T tx ty 1
Rotation cosq sinq 0
P' P R
x' y' 1 x y 1 sinq cosq 0
0 0 1
Scaling Sx 0 0
x' y' 1 x y 1 0 Sy 0
P' P S
0 0 1
Example 4 -A triangle ABC with vertices A(30,20) B ( 90,20) C ( 30,80) is to be rotated
anticlockwise direction by 30º angle. Give 3 x 3 homogeneous coordinate matrix and
find the new position of the vertices.
C The equation for the transformation is as follows P’ = P x R.
y
The 3 x 3 homogeneous coordinate matrix R is given by-
Hence the new co-ordinates are A’ [15.98 , 32.32 ] B’ [67.94 , 62.32 ] & [ -14.02 , 84.28 ]
32
INVERSE TRANSFORMATIONS
When we apply any transformation to point P(x,y) we get new point P’(x’y’).
Sometimes it is required to undo the applied transformation and thus we
get again original point P(x,y). This can be achieved by inverse
transformation.
P(x,y) P’(x’y’) Forward Transformation ( T )
.
The elements for the inverse matrix T-1 can be calculated from the elements of T as
below.
ei j
-1 = [ (-1)i+j . det Mji ] / det T
Where
ei j-1 is the element in the ith row and jth column of T-1.
Mji is the (n-1) by (n-1) sub matrix obtained by deleting jth row and ith column
of matrix T.
33
INVERSE TRANSFORMATIONS for Translation
The translation matrix is given by –
1 0 0 Elements of T-1 is
0 1 0
T
given by –
tx ty 1
35
Multiple (Composite) Transformations
It is rare that we want to perform just one elementary transformation.
Usually an application requires that we build a complex transformation
out of several elementary ones
e.g. translate an object, rotate it, and scale it, all in one move
?
T.R = R.T
Compositing Transformations
Does order matter? 1 0 2
T 0 1 0
Case 1: translate by (–2, 0), scale by (2, 2)
Case 2: scale by (2, 2), translate by (-2, 0)
Begin: red, 1st transform: blue, 2nd: green
0 0 1
2 0 0
S 0 2 0
y y
(0,6) (2,6)
(4,6)
0 0 1
38
Commutative Combinations of transformations
1. Translate, Translate
2. Scale, Scale
3. Rotate, Rotate
4. Scale Uniform, Rotate (Su .R = R .Su)
Non-Commutative Combinations of
transformations
1. Rotate , Translate
2. Scale, Translate
3. Differential Scale (Sx=/ Sy), Rotate
39
Reversing Order in which a sequence of transformations is
performed may affect the transformation position of an object.
a. T.R. b. R.T
40
Multiple (Composite) Transformations
Combined transformation can be achieved by two ways –
•Step by Step Method
•Matrix Concatenation Method
T T-1
R
10 10
10
B 10
C* B*
5
5 5
5
C” B”
A B C’
A*
X
30o
0 5 10
A’0 5 10
X 0 5 10
X 0 5 10
X
B’ A”
P’ = P. T Tresult = T. R . T-1
P’’ = P’. R P’’’ = P. Tresult
B
cosq sinq 0
R sinq cosq 0
Torotate about the pivotal point V- 0 0 1
A. We first translate all points so that V
coincides with the origin
1 0 0
T1 0 1 0 C. then all points are translated back, so
Xr Yr 1 that V is restored to its original location
A
1 0 0
T 2 0 1 0
Tresult = T1. R . T2 C Xr Yr 1
P’ = P. Tresult
Example-Rotation about Pivotal point
Perform a counter clockwise 300 rotation of triangle ABC with A(4,3), B(10,3)
and C(4,7) about vertex point A.
Y Y
Y
Y
T1 T2
R
10 10
10
B 10
C* B*
5
5 5
5
C” B”
A B C’
A*
X
30o
0 5 10
A’0 5 10
X 0 5 10
X 0 5 10
X
B’ A”
Tresult = T1. R . T2
1 0 0 Cos30 Sin30 01 0 0 0 . 87 0 .5 0
0
Tresult 0 1 0 Sin30 cos30 00 1 0 = 0 .5 0 . 87
4 3 1 0 0 14 3 1 2 . 03 1 .6 1
Ax * Ay * 1 4 3 1
Bx * By * 1 10 Ax* Ay* 1 4 3 1
3 1.Tresult Bx* By* 1 9.2
Cx * Cy * 1 4 7 1 6 1
Cx* Cy* 1 2 6.46 1
Scaling about Arbitrary Point ,P
T
P
P
Fig. A Fig. B
TST-1 T-1
S
Fig. C Fig. D
To scale an object about point P(fig A), we have to carry out following steps-
•Translate the point P to the origin is at (x0,y0). Figure(B)
•Scale it about origin by scaling factors Sx and Sy. Figure(C)
•Finally translate back to point P (Inverse translation) Figure(D)
45
Flip (Mirror/Reflection ) Transformation
1. About X axis
2. About Y axis
3. About Origin
4. About y=x
5. About y = m X +c
Flip (Mirror/Reflection ) Transformation
x-axis y-axis
1 0 0
0 1 0
0 0 1
1 0 0
0 1 0
0 0 1
Flip (Mirror/Reflection ) Transformation
About X axis
48
Other transformations
Reflection:
origin 0 1 0
line x=y
1 0 0 1 0 0
0 1 0
0 0 1 0 0 1
Flip (Mirror) Transformation
About Y axis About Origin
50
Flip about Arbitrary Axis
51
Reflection about any arbitrary axis
Tr = T.R.Fx.R-1 T-1
Reflection about an arbitrary axis
(0,0) X
(0,0) X
y=
mx
y=
+c
mx
+c
55
Shear transformations
x-direction y-direction
1 shx 0 1 0 0
0 1 0 sh 1 0
y
0 0 1 0 0 1
Shear Transformation
X Shear
57
Shear Transformation
Y Shear
58
Shear (cont.)
Example: x-direction shear
Given shx =2, relative to the x-axis ( y = 0), and a
square with coordinates (0,0), (0,1), (1,1), (1,0).
59 CS 380
Shear (cont.)
Example: y-direction shear
Given shy =2, relative to the y-axis ( x = 0), and a
square with coordinates (0,0), (0,1), (1,1), (1,0).
60 CS 380
Inverse Flip
61
Shear trans. example
62
Shear trans. example
63
Shear trans. example
64
2D Transformations
a b 0
Tr c d 0
e f 1
Non zero e, f - Translation
Non zero a,b,c,d- Rotation, Scaling, Shear
65
Coordinate Transformations
Transformation of an Object Description from
One Coordinate System to Another
Multiple Coordinate System
Local (modeling) coordinate system- (UCS)
World coordinate scene (WCS)
Local Coordinates
68
Geometric Mapping Applications
Building a 3D model
Representing actual physical object on a Display
screen
Plotting an object on O/P device
Used in assembly modeling where many parts
created in their own co-ordinate sys. Are mapped
to Assembly co-ordi. System.
To merge One part into another
Animation
69
Local (UCS) vs. Global Co-ordinates (WCS)
In practice we find that it is cumbersome in most applications to have
to recalculate the individual points that make up an object
It is more common to define the object with reference to some local co-
ordinate origin (or reference point) and axis.
We then specify through a transformation matrix how this reference
frame relates to the Global reference frame.
70
Geometric Mapping
Representing an Object from one co-ordinate system
to another. WCS, UCS,SCS etc.
Types- 1.Translation 2. Rotational and 3.General
1.Translation 2. Rotational
1 0 0 cosq sinq 0
0 1 0 sinq cosq 0
tx ty 1 0 0 1 71
Geometric Mapping
3.General Mapping – Both Translation and Rotational Mapping
cosq sinq 0
T .R sinq cosq 0
tx ty 1
72
1a. Translation Mapping- Coordinates in WCS
If Co-Object ordinates are given in WCS (i.e. Map fromWCS to
UCS ) –Transform UCS
tx= 3, ty=2
Coordinates in UCS
A(1,1) B(1,3) C(4,3) D(4,1) Coordinates in WCS
A(4,3) B(4,5) C(7,5) D(7,3)
tx= 3, ty=2
Rotate WCS in
Anti-Clockwise
A -0.366 1.366
B--0.634 3.098
C-1.964 4.598
D-2.964 2.866
Rotate UCS in
Clockwise
Ax' Ax' 1 Ax Ay 1 Cos 30 Sin 30 0 Ax' Ax' 1 0.40 1.4 1 0.86 0.5 0
Bx' Bx' 1 Bx By 1 Sin 30 Cos 30 0 Bx' Bx' 1 0.6 3.1 1 0.5 0.86 0
.
Cx ' Cx ' 1 Cx Cy 1 0 0 1 Cx ' Cx ' 1 1.96 4.6 1 0 0 1
Dx' Dx' 1 Dx Dy 1 Dx' Dx' 1 2.96 2.8 1
Ax' Ax' 1 1 1 1
Bx' Bx' 1 1 3 1
Cx' Cx' 1 4 3 1
77
Dx' Dx' 1 4 1 1
3. General Mapping
If Co-Object ordinates are given in UCS (i.e. Mapping from
UCS to WCS ) –Transform WCS
Co-ordinates in WCS
A( 1.9,4.5 ) b( 0.96,6.3)
C(3.5,7.8 ) D( 4.5,6.1)
78
3. Generall Mapping …… contt
If Co-Object ordinates are given in WCS (i.e. Map fromWCS to
UCS ) –Transform UCS
Co-ordinates in WCS
A( 1.9,4.5 ) b( 0.96,6.3)
C(3.5,7.8 ) D( 4.5,6.1)
Translate UCS
Rotate UCS
in Clockwise
79
Geometric Mapping
80
Geometric Mapping
1. The co-ordinates of triangle ABC in UCS are A(2,2) B(4,4) & C( 3,5).
The coordinate of origin of UCS in WCS are (2,2). If the X axis of UCS
makes an angle 30 with X axis of WCS. Determine the coordinates of
vertices of triangle ABC in WCS.
Ax' Ax' 1 2 2 1 0.86 0.5 0
Bx' Bx' 1 4 4 1 0.5 0.86 0
Transform WCS .
Cx ' Cx ' 1 3 5 1 2 2 1
(Xv2-Xv1) (Xw-Xw1)
Xv = ----------------------------- + Xv1
(Xw2-Xw1)
(Yv2-Yv1) (Yw-Yw1)
Yv = ----------------------------- + Yv1
(Yw2-Yw1)
83
84
85
Next Lecture …….
3D Object Transformations
scaling
translation
rotation
90
Why composition?
One of the main reasons for composing transformations is
computational efficiency
* : clever graphics systems will take into account that the bottom row doesn’t need to be
multiplied out. But even in this case Compositions takes about half the time (9N+27 vs. 18N)