Module 3 - 2D Transformations - 1
Module 3 - 2D Transformations - 1
Module 3 - 2D Transformations - 1
2D TRANSFORMATIONS
MODULE III
Two dimensional transformations. Homogeneous coordinate
systems – matrix formulation and concatenation of
transformations. Windowing concepts –Window to Viewport
Transformation- Two dimensional clipping-Line clipping –
Cohen Sutherland, Midpoint Subdivision algorithm
TWO DIMENSIONAL TRANSFORMATIONS
Changes in orientation, size, and shape are accomplished with
geometric transformations that alter the coordinate descriptions
of 2D objects.
Basic Geometric Transformations
Translation
Rotation
Scaling
Reflection
Shear
1. TRANSLATION (1)
A translation is applied to an object by repositioning it along a straight-line
path from one coordinate location to another.
Translate a two-dimensional point by adding
translation distances tx and ty to the original
co-ordinate position (x, y) to move
the point to a new position ( x ' , y‘)
x' = x + tx
y' = y + ty
The translation distance pair (tx, ty) is called
a translation vector or shift vector.
1. TRANSLATION (2)
The translation equations can be expressed as a single matrix
equation by using column vectors to represent coordinate
positions and the translation vector:
P’=M1.P+M2
xh=x.h yh=y.h
Eg:- (2,3)
Assume h=2
(2*2, 3*2 ,2 )
(2,3) (4,6,2)
HOMOGENEOUS COORDINATES
Add a third coordinate, h
A 2D point is a 3 coordinates vector:
x
y
h
HOMOGENEOUS COORDINATES
(2)
Two points are equal if and only if:
x’/h’ = x/h and y’/h’= y/h
Numbers x/h & y/h – Cartesian co-ordinates at the
homogenous point
h=0: points at infinity
useful for projections and curve drawing x
Homogenize = divide by h. y
Homogenized points:
1
HOMOGENEOUS COORDINATES
Treat all 3 transformations in a consistent way, so that they can be
combined easily
If points are expressed in homogeneous co-ordinates, all three
transformations can be treated as multiplication
Cartesian coordinate position (x,y) is represented as homogeneous
coordinate triple(x,y,h)
• Represent coordinates as (x,y,h)
• Actual coordinates drawn will be (x/h,y/h)
For Translation
• For rotation
For scaling
COMPOSITE TRANSFORMATIONS
A composite transformation is a sequence of transformations; one followed
by the other.
we can set up a matrix for any sequence of transformations as a composite
transformation matrix by calculating the matrix product of the individual
transformations
Forcolumn-matrix representation of coordinate positions, we form
composite transformations by multiplying matrices in order from right to left.
That is, each successive transformation matrix premultiplies the product of
the preceding transformation matrices.
COMPOSITE TRANSFORMATIONS
Two successive translations are additive.
Two successive rotations are additive.
Two successive scaling operations are multiplicative.
ASSIGNMENT QUESTIONS
1) Perform a 45°rotation of the triangle whose co-ordinates are A(0, 0), B(2, 2),
C(4, 2) about the origin and about the pivot point P(-2,-2)
2) Show that the order in which transformations are performed is important by
the transformation of triangle A(1, 0), B(0, 1), C(1, 1) by (i) rotating 90 degree
in clockwise direction about the origin and then translating it in the x-direction
for 3 units (ii) First Translation and then rotation
3) Create an animation of “Rabbit and Tortoise Race” using the various 2D
Transformations.
MODULE III
Two dimensional transformations. Homogeneous
coordinate systems – matrix formulation and
concatenation of transformations. Windowing concepts –
Window to Viewport Transformation- Two dimensional
clipping-Line clipping – Cohen Sutherland, Midpoint
Subdivision algorithm
WINDOWING CONCEPTS
A world – co-ordinate area selected for display is called a window
An area on a display device to which a window is mapped is called
a viewport.
Window defines what is to be displayed.
Viewport defines where it is to be displayed.
Windows & viewports are rectangles in standard position,with
rectangle edges parallel to the co-ordinate axes.
WINDOWING CONCEPTS
VIEWING TRANSFORMATION
The mapping of a part of a world-coordinate scene to device coordinates is
referred to as a viewing transformation.
Sometimes the two-dimensional viewing transformation is simply referred
to as the window-to-viewport transformation or the windowing
transformation.
Viewing Transformation
the term window refers to an area of a world co-ordinate scene that has been
selected for display picture that is selected for viewing
2D VIEWING PIPELINE
• Some graphics packages that provide window and viewport operations allow
only standard rectangles,
• but a more general approach is to allow the rectangular window to have any
orientation.
• In this case, we carry out the viewing transformation in several steps, as
indicated in this figure
VIEWING TRANSFORMATION PIPELINE (1)
First, we construct the scene in world coordinates using the output
primitives and attributes
Next. To obtain a particular orientation for the window, we can set up a
two-dimensional viewing-coordinate system in the world-coordinate
plane, and define a window in the viewing-coordinate system.
The viewing coordinate reference frame is used to provide a method for
setting up arbitrary orientations for rectangular windows.
Once the viewing reference frame is established, we can transform
descriptions in world coordinates to viewing coordinates.
VIEWING TRANSFORMATION PIPELINE (1)
We then define a viewport in normalized coordinates (in the range from 0
to 1 ) and map the viewing-coordinate description of the scene to
normalized coordinates.
At the final step, all parts of the picture that lie outside the viewport are
clipped, and the contents of the viewport are transferred to device
coordinates.
ZOOMING AND PANNING EFFECTS
By changing the position of the viewport, we can view objects at
different positions on the display area of an output device.
Also, by varying the size of viewports, we can change the size and
proportions of displayed objects.
We achieve zooming effects by successively mapping different-
sized windows on a fixed-size viewport.
As the windows are made smaller, we zoom in on some part of a
scene to view details that are not shown with larger windows.
Similarly, more overview is obtained by zooming out from a
section of a scene with successively larger windows.
Panning effects are produced by moving a fixed-size window
across the various objects in a scene
VIEWING COORDINATE REFERENCE FRAME
This coordinate system provides the reference frame for
specifying the world coordinate window
VIEWING COORDINATE REFERENCE
FRAME
We set up the viewing coordinate system using the following procedures:
First, a viewing-coordinate origin is selected at some world position:
po = (x0, y0).
Then we need to establish the orientation, or rotation, of this reference
frame.
One way to do this is to specify a world vector v that defines the viewing
yv, direction.
Vector v is called the view up vector.
VIEWING COORDINATE REFERENCE
FRAME
Given V, we can calculate the components of unit vectors v = (vx,
vy) and
U = (ux, uy) for the viewing yv, and xv, axes, respectively.
These unit vectors are used to form the first and second rows of
the rotation matrix r that aligns the viewing xv yv axes with the
world xw yw axes.
We obtain the matrix for converting world coordinate positions to
viewing
Coordinates as a two-step composite transformation:
First, we translate the viewing origin to the world origin,
then we rotate to align the two coordinate reference frames.
VIEWING COORDINATE REFERENCE
FRAME
the composite two-dimensional transformation to convert world
coordinates to viewing coordinate is
Where T is the translation matrix that takes the viewing origin point po to the
world origin, and R is the rotation matrix that aligns the axes of the two
reference frames.
CLIPPING OPERATIONS
Procedure that identifies those portions of a picture that
are either inside or outside of a specified region of space
Region against which an object is to be clipped is called a
clip window
POINT CLIPPING
The Clip window is a rectangle to the standard position, we
save a point P=(x,y) for display if the following inequalities are
satisfied:
xwmin<=x<=xwmax
ywmin<=y<=ywmax
71
ywmax
P( x, y)
ywmin
xwmin xwmax
p1 p6
Window
p7 p5
ywmin
p8
xwmax 73
xwmin
DIFFERENT CASES FOR LINE CLIPPING
1. Both endpoints of the line lie with in the clipping
area. This means that the line is included
completely in the clipping area, so that the whole
line must be drawn.
B
B
A
A
Clip
rectangle
74
2. One end point of the line lies with in the other outside the clipping area.
It is necessary to determine the intersection point of the line with the
bounding rectangle of the clipping area. Only a part of the line should be
D
drawn.
D’ D’
B B C
C
A
A
Clip
rectangle
75
3. Bothend points are located outside the clipping area and the line do not intersect the
clipping area. In the case , the line lies completely outside the clipping area and can be
neglected for the scene.
4. Both endpoints are located outside the clipping area and the line intersect the clipping
area. The two intersection points of the line with the clipping are must be determined.
Only the part of the line between these two intersection points should be drawn.
D
D’
D’
B
H
C
B C
F H'
J
A H'
G’ A
J’ G’
Clip G I’ 76
rectangle I
This algorithm divides a 2D space into 9 parts, of which only the
middle part is
visible.
This method is used:
i. To save a line segment.
ii. To discard line segment
iii. To divide the line according to window co- ordinate.
Cohen Sutherland performs line clipping in two phases:
Phase1: Find visibility of line.
Phase2: clip the line falling in category 3 (candidate for Clipping).
77
COHEN-SUTHERLAND LINE CLIPPING ALGORITHM
LEFT RIGHT
y
1010
ywmax 1001 1000
TOP
window
ywmin BOTTOM
0101 0100 0110
xwmin x
xwmax
79
Figure :Bit Code for Cohen- Sutherland clipping
Each bit position in region code is used to indicate one of four relative
coordinate positions of points with respect to clip window: to the left, right,
top or bottom.
By numbering the bit positions in the region code as 1 through 4 from right to
left, the coordinate regions are corrected with bit positions as bit 1: left bit 2:
right bit 3: below bit4: above
A value of 1 in any bit position indicates that the point is in that relative
position.
Otherwise the bit position is set to 0.
If a point is within the clipping rectangle the region code is 0000.
A point that is below and to the left of the rectangle has a region code of
0101.
region-code bit values can be determined with following two steps.
(1) Calculate differences between endpoint coordinates and
clipping boundaries.
(2) Use the resultant sign bit of each difference calculation
to set the corresponding value in the region code.
bit 1 is the sign bit of x – xwmin
bit 2 is the sign bit of xwmax - x
bit 3 is the sign bit of y – ywmin
bit 4 is the sign bit of ywmax - y.
Once we have established region codes for all line endpoints, we can
quickly determine which lines are completely inside the clip window and
which are clearly outside.
Any lines that are completely contained within the window boundaries
have a region code of 0000 for both endpoints, and we accept these lines.
Any lines that have a 1 in the same bit position in the region codes for
each endpoint are completely outside the clipping rectangle, and we
reject these lines.
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM
Step 1
Compute the regioncodes for the two end points of the
segment
Step 2
Enter a loop, within the loop check to see if both the
regioncodes are zero. Then enter the segment into the display
file, exit the loop & return
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM
Step 3
If both the region codes are not zero then take Logical AND of both
the regioncodes & check for non-zero result. If so , then reject the line,
exit the loop & return.
Step 4
If the result is 0, then subdivide the line segment from intersection
point of line segment & clipping boundary.
Step 5
Repeat steps (2), (3) & (4) for each segment.
Intersection points with a clipping boundary can be calculated using the
slope-intercept form of the line equation.
For a line with endpoint coordinates (x1,y1) and (x2,y2)
the y coordinate of the intersection point with a vertical
boundary can be calculated as
y =y1 +m (x-x1)
where x value is set either to xwmin or to xwmax and
slope of line is calculated as m = (y2- y1) / (x2- x1)
the x coordinate of the intersection point with a horizontal
boundary can be calculated as
x= x1 +( y- y1) / m
with y set to either to ywmin or to ywmax.
Example:
An alternative way to process a line in category 3 is based on binary search. The line is
divided at its midpoints into two shorter line segments. Each line in a category three is
divided again into shorter segments and categorized. This bisection and categorization
process continue until each line segment that spans across a window boundary reaches
a threshold for line size and all other segments are either in a category 1 (visible) or in
category 2 (Not visible.)
88
MID POINT SUBDIVISION ALGORITHM
An alternative way to process a line in category 3 is based on binary
search.
The line is divided at its midpoints into two shorter line segments.
Each line in a category three is divided again into shorter segments and
categorized.
This bisection and categorization process continue until each line segment
that spans across a window boundary reaches a threshold for line size
and all other segments are either in a category 1 (visible) or in category 2
(Not visible.)
Mid-point subdivision algorithm
The mid points coordinates are (x m , y m) of a line joining the points(X1,Y1)and
(X2,Y2) are given by:
X m= X1+X2/2 and
Q
Y M= Y1+Y2/2
I2 3
4
2
I1
5
8
7
6
P
Figure: illustrates how midpoint subdivision is used to zoom in onto the two Intersection points I1 and I2 with 10 bisection.
90
Comparison b/w Cohen-Sutherland and Mid-point subdivision clipping
Algorithm
91