Lecture 5 PDF
Lecture 5 PDF
On the other hand an image representing a view becomes part of a larger image ,
like a photo on album page, which models a computer monitor s display area .
Since the monitor sizes differ from one system to another, we want to introduce a
device-independent tool to describe the display area. This tool is called the
normalized device coordinate system(NDCS) in which a unit square whose
lower left corner is at the origin of the coordinate system defines the display area
of a virtual display device. A rectangular area with its edges parallel to the axes
of the NDCS is used to specify a sub region of the display area that embodies
the image. This rectangular area of NDCS is called a viewport.
The process that converts object coordinates in WCS to NDCS is called windowto-viewport mapping or normalization transformation (N). The process that
maps normalized device coordinates to discrete device/image coordinates is
called workstation transformation which is essentially a second window-toviewport mapping, with a workstation window in the normalized device
coordinate system and a workstation viewport in the device coordinate system.
Collectively, these two coordinate mapping operations are referred to as
viewing transformation (V).
Thus
and
+
=
+
Point Clipping
Point clipping is essentially the evaluation of the following inequalities:
and
where , , and define the clipping window. A point , is
considered inside the window when the inequalities all evaluate to true.
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 points(s) into
segments that are either inside or outside the window. The following
algorithms provide efficient ways to decide the spatial relationship between an
arbitrary line and the clipping window and to find intersection points(s).
Fig.5.3
In Fig.5-3, line is in category 1(visible); line and are in category 2 ( npt
visible); and line , , and are in category 3 ( clipping candidate).
The algorithm employs an efficient procedure for finding the category of a line. It
proceeds in two steps:
1. Assign a 4-bit region code to each endpoint of the line. The code is determined
according to which of the following nine regions of the plane the endpoint lies
in
1001
1000
1010
0001
0000
0010
0101
0100
0110
Starting from the leftmost bit, each bit of the code is set to true (10 or
falls 90) according to the scheme
Bit 1 endpoint is above the window =
Bit 2 endpoint is below the window = ( )
Bit 3 endpoint is to the right of the window = ( )
Bit 4 endpoint is above the window = ( )
2. The line is visible if both region codes are 0000, not visible if the bitwise
logical AND of the codes is not 0000, and a candidate for clipping if the bitwise
logical AND of the region is 0000.
For a line in category we proceed to find the intersection point of the line
with one of the boundaries of the clipping window, or to be exact, with the
infinite extension of one of the boundaries ( Fig.5-4). We choose an endpoint
of the line, say 1 , 1 , that
is outside the window, i.e.,
whose region code is not
0000. we then select an
extended boundary line by
observing
that
those
boundary lines that are
candidates for intersection
are the ones for which the
chosen endpoint must be
pushed across so as to
change a 1 in its code to a
Fig.5-4
0 ( see Fig.5-4).
This means:
If bit 1 is 1, intersect with line = .
If bit 2 is 1, intersect with line = .
If bit 3 is 1, intersect with line = .
If bit 4 is 1, intersect with line = .
Fig.5-5
= 1 + .
Where = 2 1 and = 2 1 . The line itself corresponds to 0 1 (see
Fig.5-6). Notice that when we traverse along the extended line increasing from
to , we first move from the
outside to the inside of the clipping
windows two boundary lines
(bottom and left). If we use 1 and
2 where 1 2 , to represent the
beginning and end of the visible
portion of the line, we have
and
1 = max(0, 1 , )
2 = m(0, , )
where , , and correspond
to the intersection point of the
extended line with the windows left
, bottom, top, and right boundary.
Fig.5-6
Now consider the tools we need to turn this basic idea into an efficient algorithm .
For point , inside the clipping window, we have
( =) 1 + (= )
( =) + (= )
Each of these four inequalities can be expressed as:
, = 1,2,3,4
Where
1 =
1 = 1 (left)
2 = 1 (right)
2 =
3 =
3 = (bottom)
4 =
4 = 1 (top)
Observe the following facts:
If = 0, the line is parallel to the corresponding boundary and
< 0,
0, ,
If < 0, the extended line proceeds from the outside to the inside of the
corresponding boundary line,
If > 0, the extended line proceeds from inside to the outside of the
corresponding boundary line
when 0, the value of that corresponds to the intersection point is
.
The Liang-Barsky algorithm for finding the visible portion of the line, if any, can
be stated as a four step process:
1. If = 0 and < 0 for any , eliminate the line and stop. Otherwise
proceed to the next step.
2. For all such that < 0, calculate = . Let be the maximum of
the set containing 0 and the calculated values.
3. For all such that > 0, calculate = . Let be the minimum of
the set containing 1 and the calculated values.
4. If 1 > 2 , eliminate the line since it is completely outside the clipping
window. Otherwise use and to calculate the endpoints of the clipped
line.
For C-program you may consult Hearn and Baker-Computer Graphics/Procedural Elements for
Computer Graphics, David F.Rogers,TMH
In general , the Liang-Barsky algorithm is more efficient than the Cohen-Sutherland algorithm ,
since intersection calculations are reduced. Each updates of parameters and requires only
one division; window intersections of the line are computed only once, when the final values of
and have been computed. In contrast , the Cohen-Sutherland algorithm can repeatedly
calculate intersections along a line path, even though the line may be completely outside the clip
window. And, each intersection calculation requires both a division and a multiplication.
Case the cross product of the two edge vectors for these vertices is zero. If all
vertices are collinear , we have a degenerate polygon (a straight line). Fig.6-14
illustrates the edge vector cross-product method for identifying concave polygons.
A vector method for splitting a concave polygon in the plane is to calculate the
edge-vector cross products in counterclockwise order and to note the sign of the
component of the cross products. If any component turns out to be
negative ( as in Fig.6-14) , the polygon is concave and we can split it along the line of
first edge vector in the cross product pair. The following example illustrates this
method for splitting a concave polygon.
Fig.6-14
Example
Fig.6-15 shows a concave polygon with six edges. Edge vectors for this polygon
can be expressed as
1 = 1,0,0 , 2 = 1,1,0 , 3 = 1, 1,0 ,
4 = 0,2,0 , 5 = 3,0,0 , 6 = 0, 2,0
Where the component is 0, since all edges are in the plane. The cross
product for two successive edge vectors is a vector perpendicular to the
plane with component equal to .
1 2 = 0,0,1 , 2 3 = 0,0, 2 ,
3 4 = 0,0,2 , 4 5 = 0,0,6 ,
5 6 = 0,0,6 , 6 1 = 0,0,2 ,
Since the cross product 2 3 has a negative component , we split the
Fig.6-15
The polygon along the line of vector 2 . The line equation = 1 for this
edge has a slope of 1 and a intercept of -1. We then determine the intersection
of this line and the other polygon edges to split the polygon into two pieces. No
other edge cross products are negative, so the two new polygons are both
convex.
We can also split a concave polygon using a
rotational
method.
Proceeding
counterclockwise around the polygon edges,
we translate each polygon vertex in turn to
the coordinate origin. We then rotate in a
clockwise direction so that the next vertex +1
is on the axis. If the next vertex ,+2 , is
below the axis , the polygon is concave. We
then split the polygon into two new polygons
along the axis and repeat the concave test for
each of the two new polygons. Otherwise, we
continue to rotate vertices on the axis and to
test for negative vertex values. Fig. 6-16
illustrates the rotational method for splitting a
concave polygon.
Fig.6-16
POLYGON CLIPPING
In this section we consider the case of using a
polygonal clipping window to clip a polygon.
Convex Polygonal clipping Windows
A polygon is called convex if the line joining
any two interior points of the polygon lies
completely inside the polygon ( Fig.5-7). A
non-convex polygon is said to be concave.
By convention , a polygon with vertices
1 , 2 , . . , ( and edges 1 and 1 ) is
said to be positively oriented if a tour of
vertices in the given order produces a
counterclockwise circuit.
Equivalently , the left hand of a person
standing along any directed edge 1 or
1 would be pointing inside the polygon [
see orientation in Fig.5-8a and Fig.5-8b].
Fig.5-9
The algorithm proceeds in stages by passing each clipped polygon to the next edge
of the window and clipping.
Fig.5-10a-c
The correct result consist of two disconnected parts, a square in the lower
left corner of the clipping window and a triangle at the top ( Fig.5-10b).
However , the algorithm produces a list of vertices that forms a figure with
the two parts connected by extra edges ( Fig.5-10c). The fact that these
edges are drawn twice in opposite direction can be used to devise a postprocessing step to eliminate them.
Fig.6-21 clipping a polygon against the left boundary of a window, starting with
vertex 1. Primed numbers are used to label the points in the output vertex list for
this window boundary.
Fig.5-11a-b
Whenever our path of traversal forms a sub polygon we output the sub-polygon
as part of the overall result. We then continue to trace the rest of the original
subject polygon from a recorded intersection point that marks the beginning of a
not-yet traced edge or portion of an edge. The algorithm terminates when the
entire border of the original subject polygon has been traced exactly once.
For example , the numbers in Fig.5-11a indicate the order in which the edges and
portions of edges are traced.
We begin at the starting vertex and continue along the same edge ( from 1 to 2
) of the subject polygon as it enters the clip polygon.
As we move along the edge that is leaving the clip polygon we make a right
turn ( from 4 to 5 ) onto the clip polygon, which is now considered the subject
polygon.
Following the same logic leads to the next right turn ( from 5 to 6) onto the
current clip polygon, which is really the original subject polygon.
With the next step done ( from 7 to 8 ) in the same way we have a sub-polygon
for output [ fig.5-11b].
We then resume our traversal of the original subject polygon from the
recorded intersection point where we first changes our course.
Going from 9 to 10 to 11 produces no output. After skipping the already
traversed 6 and 7 , we continue with 12 and 13 and come to an end.
The figure in Fig.5-11(b) is the final result.