2D Geometric Transformations Guide
2D Geometric Transformations Guide
Geometric
1
Introduction
Basic Transformations
The orientation, size, and shape of the output primitives
are accomplished with geometric transformations that alter the
coordinate descriptions of objects. The basic geometric
(x,y)-------------------------(x, y, 1)
4
1. Translation
A translation is applied to an object by repositioning it along a
straight-line path from one coordinate location to another. We
translate a two-dimensional point by adding translation
distances, tx, and ty, to the original coordinate position (x, y) to
move the point to a new position (x ' , y').
5
1. Translation
We can write equation as a single matrix equation by using
column vectors to represent coordinate points and translation
vectors. Thus,
6
2. ROTATION
A two-dimensional rotation is applied to an object by
repositioning it along a circular path in the xy plane. To generate
a rotation, we specify a rotation angle θ and the position (xr , yr)
of the rotation point (or pivot point) about which the object is to
be rotated.
7
Mohan Bhandari (CG)
8
Anticlockwise direction
2. ROTATION
At Origin
-
10
[Link]
A scaling transformation alters the size of an object. This
operation can be carried out for polygons by multiplying the coordinate
values (x, y) of each vertex by scaling factors sx and sy to produce the
transformed coordinates (x', y').
• sx scales object in ‘x’ direction
• sy scales object in ‘y’ direction
14
4. Reflection
(i) Reflection about x axis or about line y = 0
x
Keeps value same but flips Y value of
coordinate points
Homogeneous co-ordinate
15
4. Reflection
(ii) Reflection about y axis or about line x = 0
Homogeneous co-ordinate
16
4. Reflection
(iii) Reflection about origin
x’ = -x
Homogeneous co-ordinate
17
4. Reflection
(iv) Reflection about line y = x
x’ = y
y’ = x
20
5. Shearing
• For rotation
Here, figure-a shows the Counter Clockwise (CCW) rotation & figure-b
shows the Clockwise (CW) rotation.
26
• For scaling
• For Reflection
• Reflection about x-axis
27
Composite Transformation
With the matrix representation of transformation
equations it is possible to setup a matrix for any sequence of
transformations as a composite transformation matrix by
calculating the matrix product of individual transformation.
Forming products of transformation matrices is often referred to
29
Fixed Point Rotation
Step 1: The fixed point along with the object is translated to
coordinate origin.
30
(Xf,Yf)
Fixed Point Rotation
Step 2: Rotate the objet about origin
(Xf,Yf) 31
Fixed Point Rotation
Step 3: The fixed point along with the object is translated back
to its original position.
32
Fixed Point Rotation
Original
Image
(Xf,Yf)
(Xf,Yf) (Xf,Yf)
Fixed Point Rotation
Composite Transformation
0
0
0
Xf
Yf
1
.
Cos θ -Sin θ
Sin θ Cos θ
0 0 1
0
0
.
1
0
0
0
-Xf
-Yf
34
Exercise 1
Q. N. > Rotate the triangle (5, 5), (7, 3), (3, 3) in counter
clockwise (CCW) by 90 degree.
A:
P’ = R. P
=
.
[ ]
-5 -3 -3 35
= 5 7 3
1 1 1
Exercise 2
Q.>Rotate the triangle (5, 5), (7, 3), (3, 3) about fixed point (5, 4)
in counter clockwise (CCW) by 90 degree.
A : Solution
Here, the required steps are:
36
Thus, the composite matrix is given by
Com = T(xf, yf) . Rθ .T(-xf, -yf)
P’ = Com . P
39
Fixed Point Scaling
Step 1: The fixed point along with the object is translated to
coordinate origin.
40
(Xf,Yf)
Fixed Point Scaling
Step 2 : Scaling the objet about origin
(Xf,Yf) 41
Fixed Point Scaling
Step 3: The fixed point along with the object is translated back
to its original position.
42
Fixed Point Scaling
Original
Image
(Xf,Yf)
(Xf,Yf)
43
(Xf,Yf) (Xf,Yf)
Fixed Point Rotation
Composite Transformation
0
0
0
Xf
Yf
1
.
Sx
0
0
Sy
0 1
0
0
.
1
0
0
0
-Xf
-Yf
44
Exercise 2
Q.N.1. > Find the coordinate of a triangle A(1,3) , B(2,5) and C(3,3)
after twice its original size
a) about origin
b)about fixed point (2,3)
Q.N.2. > Find the coordinate of a triangle A(1,3) , B(2,5) and C(3,3)
Q.N.4 >Find the coordinate of a triangle (5, 5), (7, 3), (3, 3) after scaling
(2,3) and then rotate 45 CCW then translate (1,1) and then reflect y=0 45
line.
[Link] the coordinate of a triangle (5, 5), (7, 3), (3, 3) after
translate (1,0) then scaling (3,3) then rotate 45 CW then
translate (1,1) and then reflect x=0 line.
[Link] the coordinate of a line (5, 5), (3, 3) after rotate 450
ccw at fixed point (3,3) then translate (1,1) then reflect at
x-axis.
[Link] the coordinate of a point (5, 5) after reflection y-axis
Also,
The slope of the line (m) = 1 52
Thus, the rotation angle (θ) = Tan-1(m) = Tan-1(1) = 450
Here, the required steps are:
• Translate the line to origin by decreasing the y-intercept with
one.
• Rotate the line by angle 450 in clockwise direction so that the
given line must overlap x-axis.
• Reflect the object about the x-axis.
• Reverse rotate the line by angle -450 in counter-clockwise
direction.
53
Mohan Bhandari (CG)
54
Mohan Bhandari (CG)
55
Now, the required co-ordinate can be calculated as:
P’ = Com x P
57
Exercise (Imp)
Q.N> A mirror is placed such that it passes through (0,10),
(10, 0). Fin the mirror image of an object (6,7), (7, 6), (6, 9).
Solution
61
Home Work
• What do you mean by homogeneous coordinates? Rotate a
triangle A(5,6), B(6,2) and C(4,1) by 45 degree about an
arbitrary pivot point (3,3). (2072 TU).
• Use Bresenham's algorithm to draw a line having end points
(25, 20) and (15, 10). (2072 TU).
62
Two Dimensional Viewing
• Two-dimensional viewing is the mechanism for displaying
views of a picture on an output device. Much like what we see
in real life through a small window on the wall or the
63
2D Coordinate System
1. Modeling Coordinates
• Modeling coordinates are used to construct shape of individual parts
(objects or structures) of a 2D scene. For example, generating a circle
at the origin with a “radius” of 2 units.
• Here, origin (0, 0), and radius 2 units are modeling coordinates.
65
2D Coordinate System..
3. Viewing Coordinates
• Viewing coordinates are used to define particular view of the user.
Viewer‟s position and view angle i.e. rotated/translated.
• Viewing coordinates specify the portion of the output device that is
to be used to present the view.
66
View Coordinates
2D Coordinate System..
4. Device Coordinates or Screen Coordinates
• The display coordinate system is called device coordinate
system. Device coordinates are specific to output device.
• Device coordinates are integers within the range (0, 0) to
67
Device Coordinates
2D Coordinate System..
68
Window and Viewport
Window:
• A world-coordinate area selected for display is called a window or clipping
window. That is, window is the section of the 2D scene that is selected for
viewing.
• The window defines what is to be viewed.
Viewport
• An area on a display device to which a window is mapped is called a viewport.
69
Window to Viewport transformation
A window is specified by four world coordinates: Xwmin, Xwmax, Ywmin
and Ywmax (see Fig.). Similarly, a viewport is described by four normalized
device coordinates: Xvmin, Xvmax, Yvmin and Yvmax.
Window Viewport
=
=
74
Two-Dimensional Viewing Pipeline
76
Clipping..
Why Clipping?
1. Excludes unwanted graphics from the screen.
2. Improves efficiency, as the computation dedicated to
objects that appear off screen can be significantly reduced.
77
Point Clipping
• Let W denote a clip window with coordinates (xwmin, ywmin),
(Xwmin, Ywmax), (Xwmax, Ywmin), (Xwmax, Ywmax), then a
vertex (x, y) is displayed only if following “point clipping”
inequalities are satisfied:
Xwmin ≤ x ≤ Xwmax,
78
Line Clipping
• Lines that do not intersect the clipping window are either
completely inside the window or completely outside the
window. On the other hand, a line that intersects the clipping
window is divided by the intersection point(s) into segments
that are either inside or outside the window.
80
Line Clipping…
Ywmax
Ywmin 82
Xwmin Xwmax
Step 1 : Establish Region code for all line end point
• First bit is 1, if x < Xwmin (Point lies to left of window) , else set it to 0
• Second bit is 1, if x > Xwmax (Point lies to right of window) , else set it to 0
• Third bit is 1, if y < Ywmin (Point lies to below window), else set it to 0
• Fourth bit is 1, if y > Ywmax (Point lies to above window) , else set it to 0
Fourth Bit
Third Bit
Xwmin Xwmax
Step 2: Determine which lines are completely inside window
and which are not
a) If both end points of line has region codes ‘0000’ line is
completely inside window.
b) If logical AND operation of region codes of two end points is
NOT ‘0000’. The line is completely outside (some bit position
have 1’s)
C 1001
D 0001 D
AND
0001
Completely Outside 84
Step 3 : If both tests fail then line is partially visible so we need to
find the intersection with boundaries of window .
• Yi= Y1 + m (X – X1)
Window Window
90
Before clipping After clipping
Sutherland-Hodgeman Polygon Clipping Algorithm
• The Sutherland-Hodgeman Polygon-Clipping Algorithms clips a
given polygon successively against the edges of the given clip-
rectangle. It starts with the initial set of polygon vertices, first
clips the polygon against the left rectangle boundary of the
window. Then successively against the right boundary, bottom
boundary, and finally against the top boundary, as shown in
Original Polygon Clip Left Clip Right Clip Bottom Clip Top
91
Chapter 3