Beruflich Dokumente
Kultur Dokumente
FOR
C O M P U T E R GRAPHICS
by
CHAN-HUNG TRAN
T H E REQUIREMENTS F O R T H E D E G R E E O F
in
T H E F A C U L T Y O F G R A D U A T E STUDIES
D E P A R T M E N T O F E L E C T R I C A L ENGINEERING
T H E UNIVERSITY O F BRITISH C O L U M B I A
April 1986
..7
e
Chan-Hung Tran, 1986
In presenting this thesis in partial fulfilment of the requirements for an advanced degree at the The
University of British Columbia, I agree that the Library shall make it freely available for reference and
study. I further agree that permission for extensive copying of this thesis for scholarly purposes may be
granted by the Head of my Department or by his or her representatives. It is understood that copying
or publication of this thesis for financial gain shall not be allowed without my written permission.
D E P A R T M E N T O F E L E C T R I C A L ENGINEER TNG
communication only if the graphics system meets certain speed requirements. Clipping plays an
important role in the viewing process, as well as in the functions zooming and panning; thus, it is
desirable to develop a fast clipper. In this thesis, the intersection problem of a line segment against a
convex polygonal object has been studied. Adaption of the the clip algorithms for parallel processing
Based on the conventional parametric clipping algorithm, two families of 2 - D generalized line
clipping algorithms are proposed: the t-para method and the s-para method. Depending on the
implementation both run either linearly in time using a sequential tracing or logarithmically in time by
applying the numerical bisection method. The intersection problem is solved after the sector locations
of the endpoints of a line segment are determined by a binary search. Three-dimensional clipping with
Furthermore, a mapping method is developed for rectangular clipping. The endpoints of a line
segment are first mapped onto the clip boundaries by an interval-clip operation. Then a pseudo
window is-defined and a set of conditions is derived for trivial acceptance and rejection.
The proposed algorithms are implemented and compared with the Liang-Barsky algorithm to
estimate their practical efficiency. Vectorization of the 2 - D and 3 - D rectangular clipping algorithms
ii
Table of Contents
Abstract ii
List of Tables x
Acknowledgement xi
1. INTRODUCTION 1
1.1 General 1
2. N O T A T I O N A N D PREVIOUS W O R K 8
2.3 Discussion 13
iii
3.3.4 The hill and the dale of t-para 25
4.1 Introduction 33
4.2.1 Notation 34
5.1 Introduction 45
iv
5.2.4 The t'-t transform 50
5.3.1 Overview 51
6. R E C T A N G U L A R CLIPPING 55
6.1 Introduction 55
6.3.2 2 - D mapping 62
6.4.1 Definition 65
6.7 3 - D extension 74
7.1 Introduction 77
7.3.1 Overview 86
v
7.4 Some notes on the AP implementation 91
8. CONCLUSIONS 105
BIBLIOGRAPHY 108
APPENDIX A Ill
APPENDIX B 116
APPENDIX C 119
APPENDIX D 128
vi
List of Figures
Figure Page
4.3a G . vs. / and F . vs. / (this example assumes G_<0 or incr= +1) 39
4.3b G . vs. / and F . vs. / (this example assumes G _>0 or incr= -1) 40
i i t
5.3 Intersections with the side planes of a clip volume with translational sweeping 53
5.4 Intersections with the side planes of a clip volume with conic sweeping 53
6.1 The clip window and nine regions 56
vii
6.2 The region codes in 2 - D 62
6.6 Parameters tpX, t^x, tpy, and tqy for the pseudo window 68
7.1 C P U times for three types of 2 - D generalized clipping algorithms where the
7.2 C P U times for three types of 2 - D generalized clipping algorithms where the
7.3 C P U times for three types of 2 - D generalized clipping algorithms where the
7.4 C P U times for three types of 2 - D generalized clipping algorithms where the
7.5 C P U times for three types of 2 - D generalized clipping algorithms where all
line segments are entirely visible to the window polygons with area ratio=2 87
7.6 C P U times for three types of 2 - D generalized clipping algorithms where all
line segments are entirely invisible to the window polygons with area ratio=2 88
7.7 C P U times for three types of 2 - D generalized clipping algorithms where all
line segments are partially visible to the window polygon of 100 sides with area
ratio=2 89
7.8 C P U times for three types of 2 - D generalized clipping algorithms which are
viii
7.9 C P U times for 2 - D rectangular clipping of the Liang-Barsky algorithm where
7.10 C P U times for 2 - D rectangular clipping of the scalar version of the mapping
7.11 C P U times for 2 - D rectangular clipping of the vector version of the mapping
7.13 C P U times for 3 - D rectangular clipping of the scalar version of the mapping
7.14 C P U times for 3 - D rectangular clipping of the vector version of the mapping
7.17 Improvements of the vector version of the 2 - D and 3 - D mapping method vs.
A.1 Case u = v
x ; c and u^=v^, 115
C. 1 Classified cases for determining a,/3, m have the same sign and | a\^ | m| ^| 01 121
ix
List of Tables
Table Page
x
Acknowledgement
I would like to express my grateful thanks to my supervisor Dr. G.F. Schrack, whose
continuous guidance and encouragement throughout the research work of this thesis is sincerely
appreciated.
The financial support received in form of a Teaching Assistanceship from the Department of
I am also grateful for the encouragement and support of my wife, Phuong, for this thesis could
never have been done without her enduring understanding and patience.
xi
1
Chapter 1
INTRODUCTION
1.1 General
graphics. They are effective only, however, if they can be performed in real-time. In
general, real-time operations can be achieved with expensive hardware, or, alternatively,
with moderately priced hardware which limits the functionality of the operations.
Embedded in the functions, clipping algorithms which are fast to run in software and
related problem discussed in Computational Geometry. Both deal with efficient ways to
find the union, intersection, and difference of two objects in a wide sense. The
the difference of an image with a defined region called the clip window in 2 - D or
the clip volume in 3 - D . The clipping process is to remove the exterior portion (interior
clipping) or the interior portion (exterior clipping) of an image to the clip window or
the type of clipping is called line clipping (Fig. 1.1). The extention of line clipping is
2
then called polygon clipping such that the resulting polygon can be filled (Fig. 1.2). In
this thesis, the intersection of line segments with a convex polygonal window or volume
is considered. The intersection problem is the second step of the complete clipping
algorithm mentioned earlier. The intersection operation is performed after it has been
determined that the two objects are possibly interfering using one of the algorithms in
[Maru72], [Chaz80], and [Dobk83]. Then, the resulting intersection points of this step
are used to outline the real shapes of polygonal objects which are inside or outside the
clip region such as in the Weiler-Atherton algorithm [Weil77] or the Weiler algorithm
[Weil80].
(see details in [Newm] and [Fole]). The object to be viewed is described by geometric
coordinate data in world coordinates. The viewer can specify a clip region which he
wishes to have displayed and a viewport, the portion of the view surface into which
the window contents are mapped (Fig. 1.3). Mapping points which are outside the
window may produce undefined values, resulting in attemps to address locations beyond
the physical limits of the display device. Such situations can be prevented by clipping.
Furthermore, clipping leads to a substantially smaller amount of work for the display
hardware to process.
identify where time is being spent mostly. In a time analysis of a flight simulation
program, it was found that only 5% of the time was spent on performing matrix
multiplication operations, while the largest block of time (23%) was spent on clipping
([Artw, p. 142]). The high percentage implies that a significant saving in processing time
Three-Dimensional line-clipping examples: (a) interior clipping
Fig. 1.1
(b) exterior clipping (from [Roge85]).
Fig. 1.2 Three-dimensional polygon-clipping examples: (a) interior clipping and
(b) exterior clipping (from [Roge85]).
to solid modeling using Constructive Solid Geometry (CSG) and oct-tree representations
[Roth82] and [Carl85]. Besides computer graphics, clipping has been exploited in many
other disciplines, e.g. robotics (object interference problems) [Boys79], [Ahuj80], and VLSI
executed in scalar processors or parallel processors. For example, the clipping algorithm
has been implemented in hardware rather than software for interactive graphics
([Spro68], [Clar80], [Mehl84]). Thus, the algorithm should be simple enough for
parallel processing aim to improve execution speed. Therefore, the following considerations
Geometry are asymptotically fast, the efficiency might not be achieved due to a large
those algorithms using complicated data structures in pursuit of theoretical efficiency (see
segments to be clipped and let N be the number of sides of the window polygon. In
algorithm consists of an inner loop (N iterations) and an outer loop (M iterations); thus
reject or accept a line segment for intersections are always the limiting factor to make
the clipping algorithm elegant, tradeoffs between extensive mathematical calculations and
likely that the clipping process is suitable for parallel processing. Moreover, because the
in order to improve the execution speed. The main concern is how to detect the
visibility of a line segment against a clip window with large N and how the
This • thesis is divided into eight chapters. In Chapter 2, we will review previous
work and some preliminary results, after establishing the notation and conventions which
are used throughout the thesis. In Chapter 3, a generalized 2-D parametric clipping
algorithm, called a t-para method, will be discussed. A sequential tracing method and a
rectangular 2-D and 3-D clipping is presented. The clipping process relies on a
remarks will be made and further avenues for research will be suggested.
8
Chapter 2
N O T A T I O N A N D PREVIOUS WORK
introducing the notation which will be used throughout the thesis. The notation given
A line segment is represented by uv, where u ( u , u^,) and v(v , v ) are its
x x
two endpoints. While the direction vector D = v-u denotes the directed line segment uv
from a point u to a point v, L denotes the directed straight line of infinite extent
which contains uv and has the same direction as uv. The inner normal vector D of D
on) L if
T = zu • JQ = (u^-ZjXv^-up - (u -z )(\ -u )
y y x x ... (2.1)
(z -\i )/(v -u ).
y y y y
parameterized form as
or
i = n + tD ... (2.3)
9
zx = u x + t(v -u )
x x
... (2.4)
The parameter t, called the t-para, determines where the point lies on L The
values t=0 and t = l correspond to the endpoints u and >, respectively. If te[0,l] then
the line segment uv is traced out; tc^o , ) generates the infinite line L.
0 00
We assume that the clip window P is a single convex polygon, which consists
of a sequence of straight-line edges such that they form a cycle and such that no two
edges intersect, except at their endpoints. We represent the polygon by a circular list of
its vertices P (Wi,w 2 w^), where the points Wi.w, are the vertices and i T ^ ,
.... viflVi are the sides or the boundary edges. We also assume that two consecutive
edges are not collinear. Each vertex is defined by its x- and y-coordinates w.(w (/),
w^(/)) and each edge is' represented by its two endpoints e.=vx. + ^ 2.1). Note
that index addition and subtraction is taken modulo N . The directed infinite straight-line
containing the edge e^. is called its boundary line and is denoted by L.. L. has the
w
14
w
7
By this convention, the inner normal vector of the edge e., viz.,
JE ( y['+l)-w^(/),
i
w
~[w (/+l)-w (/)]),
J| Jt always points to the
can draw two lines of support parallel to L and passing through a pair of antipodal
points R and S of the clip polygon (Fig. 2.1). If L points from the exterior of L. to
the interior of L., then the boundary edge e^. is called an entry boundary to uv; if L
points from the interior of L. to the exterior of L., then the boundary edge is
called an exit boundary. Two chains of boundaries are formed: an entry chain denoted
by chain! consisting of all entry boundaries and an exit chain denoted by chain2
11
In this thesis, only exterior clipping is considered. The visible region is the
interior of the clip window. A line segment is classified as entirely visible, entirely
invisible, or partially visible to the clip polygon. The following degenerate cases are
considered to be visible to the polygon: the line segment touches the polygon at one
point or eitheT a portion or the whole of the line segment coincides with a boundary
Two equivalent algorithms are proposed in the literature which satisfy the
considerations (2) and (3) of Section 1.3. The idea of using a parametric representation
of a line for intersection testing were independently proposed by Cyrus and Beck
[Cyrus78] and Liang and Barsky [Lian83, Lian84]. Cyrus and Beck use a geometrical
segment and a boundary line, while Liang and Barsky describe it in an algebraic form.
programming problem. We will decribe the above method differently, which is adapted
to our notation.
finding the intersections of the line segment and all boundaries of infinite extent, then
12
imposing a parametric range restriction. Let f be any point on the extended line J L of
V(ttu.*]-f) = 0
- <-)
2 5
t (z) =
uv
A (z) / B (/)
u UV
... (2.6)
Where
A (/) =
U
£ / .(f-u),
(2.7)
B UV
(/)= £ / -(v-u).
A (/) =
U
m - E (/)
U
(2.8)
B (/) =
uv
E (/) -
V
E (/)
U
«i • (t[u,v]- f )
exterior interior
3.3.1 and 3.3.2. The notation t (/) denotes the t-value of the intersection point of the
1. te[0.1],
2. £ .'(t[u,v]-f) >
| 0,
2.3 Discussion
2
For the B ( / ) = 0 case (line segment parallel to the corresponding boundary line), t (/) is
uv uv
defined as [Lian84]
© 0 = + « if ( B ™ ( i ) = 0 ^nd. A (/)>0), u
t ( / ) = - » if (B (/)=0 jo±
u v uv
A (/)<0). u
In the implementation, however, the B (/)=0 case is treated separately by testing the sign of
A ( / ) : if positive then the line segment is invisible, else visible.
u
14
36, 40, 79 percent improvements have been gained over the conventional
Sutherland-Cohen algorithm for 2-D, 3-D and 4-D (homogeneous coordinates) cases,
respectively [Lian84]. The parameter t not only contributes to determine early rejection
but also is used to compute the coordinates of the intersection points if accepted.
Lemma 2 helps to determine quickly if a line segment diagonally bypasses the clip
window, while the conventional test (e.g. the Sutherland-Cohen algorithm [Roge] or the
before rejecting it Since the parameters t are independent with respect to the
However, the conventional parametric algorithms are slow if 'the size of the
clipping polygon is large. Since it must compute t-para's with respect to all boundaries
in the worst case, O(N) operations are required. The key observation is the following:
if the location of the endpoints u and v can be identified, much effort can be saved
in computing the t-para set because a large number of boundaries is eliminated from
2. how to utilize the location information to reject quickly the line segment if it is
partially visible.
15
Chapter 3
T H E T W O - D I M E N S I O N A L T - P A R A CLIPPING A L G O R I T H M
In this chapter, two variations of the 2-dimensional t-para clipping algorithm are
proposed. Unlike the conventional parametric algorithm the 2-D space is divided into
angular sectors for detecting quickly the location of endpoints. This approach was first
M-gon with a convex N-gon. Since we do not restrict the shape of the objects that
can be clipped except that they are formed by line segments, our algorithm is
applicable to clip non-convex objects to a convex region. By knowing the sectors which
contain the endpoints, 75% of the boundaries are, on the average, eliminated from
intersection testing (see Section 3.4.4). Thus, a small investment results in considerable
Let c be any point interior to the window polygon P (e.g. the mass center of
P), then the semi-infinite rays emanating from c and drawn through the vertices of P
partition the plane into N angular sectors as shown in Fig. 3.1. Because P is convex,
no sectors or regions will overlap. This assures the uniqueness of the sector belonging
to an arbitary point in the 2 - D plane. To simplify the discussion, we assume that the
points of interest do not coincide with the center c. As shown in Fig. 3.2, a binary
tree (BT) is generated which stores the slopes of the semi-infinite rays cw^., /e[l,N].
Then the sector containing a point can be found by a binary search. The binary search
will cost O(logN) after O(N) preprocessing time [Sham75]. The endpoint u of line
segment uv lies in the sector formed by the boundary e, (see Fig. 3.2), if the
16
be similarly identified.
During preprocessing, the necessary polygon data (e.g. s.^ and E(/)) are also
precomputed and stored. The generation time of the binary tree as well as the polygon
processing time drops to nearly zero as the data base of clipped line segments grows.
Therefore, if we consider clipping a large set of line segments, the overhead time for
each line segment is negligible. This approach only yields advantages if the polygon data
can be precalculated and reused for each line segment The time complexity now
polygon P after the regions belonging to its endpoints have been identified. As shown
Case 1 Points u and v lie within the polygon P, no intersection with the
boundaries of P occurs.
intersection occurs.
Case 4 Both u and v are outside P in different sectors, uv may or may not
(a) Case 1 (b) Case 2
V
(e) Case 5
intersect with P.
Case 5 One of the points u and v is inside and the other is outside in a
polygon P at one point, we only need to determine where the intersection point is.
Case 4 is the worst case consideration: we need to determine first whether uv intersects
P and, if it does, which boundaries it intersects. Because the solution determining the
location of the intersection points for case 4 and case 5 is similar, case 4 is more
difficult than case 5. Thus we need to concentrate on case 4 where u and v lie in
In this thesis we propose two visibility testing methods utilizing parametric line
representations called the t-para method (Chapter 3) and the s-para method (Chapter
4). Both methods can be executed linearly in time by tracing edges sequentially or
The treatment of A ( / )
u
and B ( / )
uv
is only mentioned briefly in [Cyru78] and
[Lian84]. Nevertheless, they are very useful in determining the visibility of the line
A (/)u
is the dot product of vector uF and the inner normal vector £ . of e „
The sign of A ( / )
u
indicates the half plane of J L on which the endpoint u lies. If
A (/)
u
is positive (negative, zero), point u lies to the exterior of (interior of, on) the
boundary line L.. The absolute value of A (z) is not the minimum distance from u to
u
20
Since B ( / ) is the dot product of uv and the inner normal vector £.., Its sign
uv
zero), L is aiming from the exterior to the interior of (from the interior to the
exterior of, is parallel or collinear to) L.. Alternatively stated, uv is aiming towards L.
if B (/)>0
uv
or uv is aiming away from L. if B (/)<0. uv
interior(u,L^ expresses the relative location of point u with respect to L., while
(Fig.3.4 cases b, c, e, f, and g) then the line segment uv is entirely visible or entirely
invisible with respect to L.. However, if «'m(uv,Z.p is true (Fig. 3.4 cases a and d), a
further test is necessary to determine whether or not uv intersects L.. Predicate cross is
used for this purpose. If crossiw^j) is true then uv intersects L . and a portion of the
u lies in the exterior or the interior half plane of L.; otherwise uv is entirely visible
Li 21
: (b)y> j <dy u
' V
ei ei
V
(a) (c)
A (i )>0
u
A (i )<0
u
A (i )>0
u
A (i )<0
u
B (i)>0
U V
B (U<0
U V
exterior interior
(e) * 1 (g)
3
A (i )<0
U
A (i )>0
U
B (i)=0 U V
Li
: a^u
v
iv Note: The predicate CrossiwM) is
true for segments a, b and c only.
or entirely invisible because uv terminates on the way pointing towards L. but does not
uv
cross it (see Fig. 3.5). Note that the predicates aim and cross assure Q^t (/') and
t (/*l.
w
Combining all predicates, the visibility of the line segment uv with respect to
and cross, the relationships among E(/), E (/), and E (/') can be tested for saving the
u v
u uv uv
calculation of A (/), B (/), and t (i) (Table 3.1). A more efficient visibility test using
these E parameters is described in Algorithm 3.2. It should be noted that the visibility
visible{u\,Lp = vu/We(vu,Lp
and
t (/) =
uv
l-A/).
Let us consider the visibility "problem of a line segment with respect to the
polygon P. By convexity, each boundary line supports the polygon. Therefore, the visible
region defined by the polygon P is the intersection of the interior half planes of all
L., ie[l,N]. A line segment uv is said to be visible (entirely or partially) with respect
to P, if
N
.and. visible{a\,L) = true.
i=l
This implies that the visibility of a line segment against a polygon can be determined
a trivial rejection can be established. For both u, v lying in the exterior of P, the
Recall that chainl and chain2 are the chains of entry and exit boundaries. As
shown in Fig. 3.6, condition (3.4) trivially rejects all segments with k,le chainl or
ik,/echain2, because one of the visibility test against the boundaries and fails.
E (i)<E (i)
v u
B (i)<0
uv
exit boundary
E (i)<E (i)<E(i)
v u
B (i)<0<A (i)
uv u
false false false false entirely invisible
E (i)<E(i)^E (i)
v u
B (i)<A (i)_sO
uv u
true true true true partially visible
E(i)<_E(i)<E(i)
v u
A(i)__;B (i)<0
u uv
true true false true entirely visible
E«(i)=E (i) v
B (i)=0
uv
parallel boundary
E (i)=E (i)<E(i)
u v
0=B (i)<A (i)
uv u
false false false false entirely invisible
E(i)r^E (i)=E (i)
u v
true false false true entirely visible
A (i)<_B (i)=0
u uv
t-para's of uv with respect to the entry boundaries and exit boundaries generate two
unimodal functions with a hill for chainl and a dale for chain2 (see Fig. 3.7). By
Lemma 2, uv intersects P if and only if the maximun t-para against the entry
boundaries does not exceed the minimum t-para against the exit boundaries. If so, uv
and d indicate the boundary indices corresponding to the hill and the dale, respectively.
will speed up the detection and intersection problem. By knowing that the segment uv
lies in the combined sector which is bounded by the intervening edges, called the
intervening chain, a naive algorithm can be established to calculate the t-para's within
the range [k,l] and to eliminate the edges out of range. As a consequence, by saving
the t computations, it runs faster than the conventional parametric algorithms which
Algorithm 3.3. However, the actual implementation is different from the description
mentioned in the previous sections, since the t-para algorithm can be made more
compact and elegant In the next sections, we will discuss two variations of the t-para
method, the sequential tracing method and the bisection method, one of which will
26
(boundary
index)
B (i)>0
uv
B (i)<0
uv
B (i)=0
uv
max_tO
min_t1
i (boundary
index)
B (i)>0
uv
B (i)<0
uv
B (i)=0
uv
UV
Fig. 3.7 t (/) vs. / (this example assumes G <0 or incr= + l).
27
As mentioned earlier, we only need to compute the t-para's of the edges within
the intervening chain. The searching process of the minimax values of the t-para's can
compute the t-para's of the entry/exit boundaries, in pairs, such as (e^, e^), ( £
e
+ z n c -»
fast rejection, where incr might be +1 (front trace: trace in C W direction) or - 1 (back
trace: trace in C C W direction). The tracing directions depend on the relative location of
G c = D-(u-c);
The algorithm maintains two edge pointers for tracing chainl and chain2. These
the tracing rule such that the edges in chainl and chain2 are "chased" one by one to
search the intersection points. Examples of boundary tracing are shown in Fig. 3.8. It
should be noted that in case 5 only one direction of tracing is necessary: if u«T then
entry tracing otherwise exit tracing with the same tracing direction as case 4.
L
An important consideration for an algorithm are the stopping rules. First, since
the intervening chain is bounded by [&,/], the tracing can not exceed these extrema.
We also define a tighter bound for each direction of tracing. To simplify the discussion,
assume that c is on the right to L. Entry tracing stops when it traces from chainl and
UV
passes an antipodal vertex, i.e. B (/) changes sign from positive to negative/zero (see
UV
Fig. 3.7 again). Similiarly, exit tracing terminates if B (/) changes sign from negative to
postive/zero. Recall that the purpose of tracing is to find the minimax values of
t-para's. The entry boundaries are traced uphill such that ^ e n t r y is approaching max_tO
from e^. and reversely the exit boundaries are traced downdale such that t ^ is
approaching min_tl from e^. The entry tracing stops when it just passes over the hill
UV
of t-para and begins to face downhill (t (/) turns to decrease); the exit tracing
turns to increase). Therefore, tracing only occurs within the ranges [k,h + incr] and
[d-incrj] and the inner boundaries [h + 2-incr, d-2-incr] corresponding to the hill and
the dale of t-para are eliminated from tracing. This indicates the significant saving of t
computations if the sectors belonging to the endpoints of a line segment are known.
It should be noted that although both boundary tracings start at the same time
from e^. and respectively, one might terminate earlier than the other during the race
to reach max_tO or min_tl. The entire tracing process ends when both have terminated
tested with chain2 for intersections rather using uv. Note that t ^ / ) = l-t (/).
uv
Let
max_q0 = l-min_t0. Then, instead of searching min_tl we can search the maximum
value (max_q0) during the entry tracing of vu starting from e^ and following the -incr
direction. The tracing procedure can be simplified to deal only with entry tracing as
Algorithm 3.4b.
The tracing time is O(N). Because the shape of the clip polygon is arbitrary, it
approximated circle with sides of equal length and c as the center, then the tracing
range is equal to half of the polygon (circle) perimeter for the worst,case. Imagine an
infinite line parallel to the line segment uv and passing through c. This line will
divide the circle into two half planes one of which contains the segment uv. It is easy
to see that at most half of the circle perimeter needs to be traced. Thus, for the
worst case 50% of the polygon edges are needed to determine intersection. Therefore, on
the average the t-paxa sequential tracing method needs only an evaluation of 25% of
the parameters L However, the time complexity is still O(N) because the computational
complexity eliminates the multiplicative factors. On the other hand, the conventional
parametric clipping algorithms always compute all t-para's (N times) in order to find
Let us consider the possible use of parallel processing for the t-para sequential
clipping algorithm. There are two levels of parallel executability. The entry tracing and
31
exit tracing independently update the global variables max_tO and min_tl, respectively.
They are suitable for parallel implementation. Furthermore, each t-para needs two
uv
We know that the t-para function ( t (/") vs. /' ) is a bimodal function with a
minimum value (min_tl) and a maximum value (max_tl) within [k,l]. To simplify the
uv
discussion we suppose k<l for incr= + l. .Because the t (/) corresponding to the
bounding edge e^. of the intervening chain is not known, it is possible to apply an
uv
logarithmic approach, called the bisection t-para method, which is based on the
the hill and the dale of t-para are h and d, respectively. The algorithm consists of
three steps:
1. First, we find the boundary range [k,m] of the entry chain (B (/)>0) such that uv
the boundary with max_tO lies within it, i.e. he[k,m]. Similiarly, [n,l] contains the
half the boundaries in each iteration such that the range is alternately narrowed
from both ends on the way finding the maximum or minimum value. In each
iteration, the mid-boundary of the range is found and the first derivative t' =
1
mid+incr~ mid *l S c o m
P u t e c
^- ^ l
'mid * S
P° ^
s v e
( 8 ne auve
) > then the walk from
the mid-boundary to the next boundary faces uphill (downdale). Since we assume
32
that consecutive boundaries are not collinear, no ^ ' ^ is equal to m zero. In the
the line segment is invisible; otherwise the intersection coordinates are computed
A formal description of the algorithm is given in Algorithm 3.5a, 3.5b, and 3.5c.
From the discussion in Section 3.4.3, the "find-minimum" of t-para in exit tracing can
implementation.
Since after each iteration half of the edges are eliminated, the algorithm runs in
time O(logN). However, this approach has a large constant factor, because i t , must
expensive l-para calculations result in a reduced efficiency of this algorithm, despite its
they can be computed in parallel to speed up the processing time. Furthermore, once
the ranges [k/n] and [nj] have been identified, the operation finding the minimax
values within these ranges can be implemented in parallel. The interval-halving operation
has been taken in the midpoint subdivision technique which was implemented in Sproull
and Sutherland's Clipping Divider [Spro68] and Clark's Geometry Engine [Clar80].
33
Chapter 4
4.1 Introduction
In this chapter, a new 2 - D clipping algorithm called the s-para method will be
described. This method is based on the segment-line intersection technique in which the
idea that if two endpoints of a line segment lie in opposite sides of a line then the
line segment intersects this line is employed. We test the edges within the intervening
chain to see whether they intersect the infinite line L which contains uv. This test is
performed only for the line segments which- can not be trivially rejected. The search
cost for intersecting edges of this method is lower than that of the t-para method.
Similar to the t-para method, both sequential search and bisectional search techniques
are applicable; nevertheless, this method is more promising for the development of a
The s-para algorithm is a variation of the t-para algorithm for the "worst
case". Thus, it is necessary to replace step 4.2 in Algorithm 3.3. Recall that the worst
case occurs either when an endpont lies inside P and the other lies outside or when
both endpoints lie outside P with e^echainl and e^echain2. By exchanging the role of
(u\,L.) with (e^-.L), we consider in this section the intersection problem of edges of
4.2.1 Notation
To avoid confusion with the notation which was used for the t-para method, we
__>(v - u , -(v - u ) ) .
v r Let g be any point on L and Wm. be a boundary edge of P.
y y ~ i j
A Wj. + s.j(Wj-Wj). The parametric value s.j is called the s-para in short The s-para
of the intersection point of L and L. is defined by the following equation (see also
Fig. 4.1)
... (4.1)
i g ... (4.2)
H.. = F . - F.. = G. -
ij J
14 LS
£(g Wj)>0
g L
c(g
Wi)<0
LR
7
Fig. 4.1 Basis of s-para method (this example assumes c is on the right to L)
35
G «G .<0:
c / yt. lies on the opposite side of c with respect to L,
Notice that the case where c lies on L ( G = 0 ) does not occur here, c because this
Let w f l and be the starting and ending vertices of the intervening chain,
respectively. According to the tracing direction rule defined in Section 3.4.1, indices a
and b can be defined by the indices k and / corresponding to the starting and ending
a — k-incr
b = I
endif;
point u lies outside of P then point w lies on the same side of c with respect to L.
fl
A similar argument applies for point v and point w^. Ignoring the case where both
points u and v lie interior to P, the initial conditions are summarized as follows:
1. i f u * P then G -G >0
f l c else G -G <0
fl /; JOJ. G fl+/|IC/ . - G <0
6 endif;
(G .G >0
f l f c .and. G a + t M r -G Z0) b ss.
( G . G > 0 and.
f l f c G.-G^ZO)
endif;
Let us assume that two adjacent vertices m. and w^. are found to be G. • Gj£ 0.
Then the infinite line L intersects edge wlv. at a point z = w.+ s..(w -w.), given s..
° i j v
i ij j i ij
by (4.1). This case occurs when line L lies inside the slab formed by L^ and L^.
Since the cases where both endpoints fall in the exterior region of either chainl or
chain2 have been trivially rejected (see Fig. 3.6 again), the line segment uv must
intersect the edge WjHj at exactly the same intersection point, In contrast, if all vertices
in the intervening chain satisfy G ^ « G > 0 , c ke[a,b], then the line L (i.e. the segment
uv) is entirely invisible because all vertices of the intervening chain fall in the same
The naive s-para method is sequentially tracing the entry chain and/or the exit
chain within [a,b] according to the tracing directions defined in Section 3.4.1. During
vertices change sign. If G.-GSO then the edge « x intersects uv, where j=i+incr for
entry tracing or J=hincr for exit tracing; otherwise the tracing continues. The tracing is
terminated if either the intersection edges (one or two) have been found or the entry
37
and exit tradng have met each other. Because the quick reject condition ( t
e n f r ^- > t
e X j ^
t
is no longer applicable to the s-para method due to the different nature of the
parameters, all G-values within the intervening chain must be computed and their signs
must be tested in order to reject uv. This is the major demerit of this algorithm The
formal description of this sequential method has been omitted because of its simplicity.
employ the bisection method to identify the antipodal point R or S which is within
(incr= + 1 ) as shown in Fig. 4.2, so that we trace the boundaries in the C W direction.
A boundary is represented by W J W . , where j=i+incr. In this case, all entry edges are
aiming away from L (H^.<0), all exit edges are aiming towards L (H„>0). If the
edge is parallel to L then H^.=0. Therefore, we have G > G ^ . ( F . < F \ ) for entry edges
because H..<0 and G . < G . ( F . > F . ) for exit edges because H..>0.
6
Due to this fact
ij j i J i ij
the parameters G^. and F . are unimodal functions with respect to the vertex indices (see
Fig. 4.3a). It is easy to determine whether an edge belongs to the entry chain or the
exit chain by comparing the parameter values G or F of its endpoints. The same
arguement is applied for the case where c lies on the left to L. It should be noted
that in the former case the parameters G (resp. F) has a maximum (resp. minimum)
value, while in the latter case the parameters G (resp. F) has a minimum (resp.
on the unimodality of the function G. vs. / or F . vs. /, ie[a,b]. The algorithm consists
intervening chain and check the mid-vertex w^.^ to see whether its G value has a
different sign than G . c If so, the find-podal-point process terminates and the
intervening chain is divided into [a,mid] and [mid,b] for intersection searching
(find-intersection-edge). Otherwise, we check the mid-vertex and its next adjacent vertex
the G (resp. F) values increase (resp. decrease) then the edge e belongs to chainl,
increase) then the edge e -^ m/ belongs to chain2, we replace the ending vertex w^, by
*rnid' o t n e r w
* s e
tw is parallel to the corresponding boundary edge and thus is trivially
rejected (see Fig. 4.3a again). The process iterates shifting both starting and ending
vertices w fl and closer and closer to L towards the antipodal point R (see examples
in Fig. 4.4). If no intersecting edge is detected during the halving iterations, then the
Fi<F (Gi>0)
f l
Fi= F ( G i = 0)
fl
Fi<F (Gi>0) f l
Fi=F 0 (Gi=0)
Fi>F (Gi<0) f l
Fi decreases Fi increases
Gi increases Gi decreases
Fig. 4.3a G . vs. i and F, vs. / (This example assumes G - < 0 or incr= +1)
>
Chain2 Chainl
}
incr=-1
i o F
b a
Fi= F ( G i = O )
0
0
H\ /\
exit entry
Fi>F f l (Gi<0) DOint \ point
Fi
Chain2 Chainl
Fi decreases' Fi i n c r e a s e s
Gi i n c r e a s e s G
i decreases
F i < F ( Gj > 0 )
g
Fi = F fl (Gi=0)
Fi>F f l (Gi<0)
(b) r e j e c t e d case.
antipodal point R is finally found and uv is rejected because all vertices within the
vertices straddling the line L have been found (their G-values have opposite signs). We
each iteration, the sign of the G parameter of the midpoint is monitored. For a
partially visible line segment with two intersection points, two ranges [a,mid] and
[mid,b] are to be searched. However, for the case of one intersection, only one
Since each iteration eliminates half of the vertices from consideration, the time
Recall that the tests which are used to identify intersections in the t-para and
s-para methods are different for sequential tracing. The t-para method computes the
t- para's corresponding to the boundaries within the intervening chain and searches for
the minimax values, while the s-para method does not need to compute the actual
s-para's. Rather, the G—values corresponding to the vertices are tested for a change of
sign. We consider the computational cost of the E and F parameters, which require two
multiplications and one subtraction, to be equivalent For two adjacent edges e^. and e^.,
calculate E (/),
u
E (/),
v
E (y") and E (y)
u u
to obtain t (/) and t (y) (more
uv uv
subtractions
and divisions are required). It is obvious that the t-para sequential method is slower
than the s-para sequential method in determining intersections, while the former is
faster than the latter in determining rejections. Hence, it is difTicult to evaluate which
one is superior.
Despite employing the binary search technique, the t-para bisection method is
very expensive due to the fact that two t-computations are used for each iteration of
searching the hill or the dale. On the other hand, the s-para bisection method needs
to calculate two G parameter values in finding a podal point and one G parameter in
finding the intersection edge for each iteration. Since the computational cost of the G
parameter is less than that of the t-para, the s-para bisection method is more
attractive. In addition, to achieve faster speed we can use the parameter F in the
Moreover, the t-computaion needs E(z) and while the s-computation does not
need these values. However, the coordinates of the polygon vertices are still needed for
the s-para method.
45
Chapter 5
5.1 Introduction
sweep-defined object, then the line-solid intersection problem is easy because of the
onto the contour plane which contains the 2-D clip window. Then, the projected line
segments are compared with the window polygon using any standard 2-D clipping
algorithm.
The technique which reduces the 3-D intersection problem to the 2-D
intersection problem is not new, in [Kaji83] and [Wijk84] the intersection problem of a
ray with sweep-defined objects has been discussed for ray casting applications. Kajiya
solved the 3-D ray tracing problem for translational sweeping (prisms) and rotational
sweeping (surfaces of revolution) in which the plane curves are represented by a strip
tree. On the other hand, van Wijk introduced rectangle tests for improving detection of
a ray with an object defined by translational, conic or rotational sweeping with a cubic
spline contour. Here, we will limit the contour to be a convex polygon so that the clip
with the intersection problem of line, segments with the clip volume. Two kinds of
transformation, or along a space curve). In this thesis, the line contour is described by
a convex polygon (clip window); translational sweeping and conic sweeping are employed
volume in a local coordinate system such that the objects to be clipped are transformed
coordinate system [Roth82]. In this approach, clip volumes are never explicitly
transformed; the scene-to-local transformations are used only to transform those objects
which have been detected to be possibly intersecting with the clip volume. Note that
Let (x,y,z) be the local coordinate system. For convenience, the contour is
embedded in a plane known as the contour plane which is parallel to the x-y plane
with z = l . The contour is described as a convex polygon P in terms of its vertices (w,,
w 2 w^y) by local (x',y')-coordinates on the contour plane where the x'- and y'-axes
plane with plane equation z = z , w to be translated to the yon plane with plane equation
47
z=Zy (Fig. 5.1). By convention, 0 < z ^ < Z y . The sweep thickness h = Z j - - z ^ is called
the height of the clip volume. With translational sweeping, the size of the cross section
is constant as it is swept parallel to the x-y plane. The clip volume is then defined as
the union of the hither plane, the yon plane and the side planes which are described
by the set of quadrilaterals (sides of the clip volume) given by the locus of the clip
window.
(x'.y')-coordinates by
x = x\ y = y\ ... (5.1)
z=z Y
h i t h e r plane
z=z H
(a) C c o i n c i d e s w i t h 0'.
after the scene-to-local transformation. An arbitrary point w(w , w^,, w ) x z on the line L
and w are projected onto the contour plane to give the two-dimensional representation
where u'=u denotes the 3-D to 2-D vector assignment such that u ' = u u'=u •
* •* y y
similarly for v' and w\
transformed to become a line L passing through their projected points iT and v'.
Hence,, the projected point w' of the point w is also on the projected line L\ The
point w' is designated by a parameter value t' as w' = t'.u'.v*] A (l-t')u'+ t'v' in the
local (x'.y')- coordinate system. Because of the orthogonal projection property, the
t = t\ ... (5.3)
contour: scaling and translation. The standard scaling of the cross section is defined by
multiplying the x- and y-coordinates by its z-coordinate. With conic sweeping, the
shape of the cross section is the same as the original contour (clip winodw) but its
size is proportional to its z-coordinate. Assuming z>0, the position of a point (x,y,z) is
defined in (x',y')-coordinates by
x = zx', y = zy\
or
Then, the projected points u \ v' and w' of the points u, v and w are, respectively,
50
defined by:
u' = u / u . z
we have
or
then we find
t = ^ k l ^ l ... ,
( 6 )
Substituting w =(l-t')u /u
x x z + t'v /v ,x z w* =(l-t')u / u z + t'v / v z into (5.6), the
V
t = ... (5.7)
v n-f) + u,f .
original line L by using Equation (5.3) or (5.7) depending on which kind of sweeping
is employed. Each point on the line L or the line L' is designated by a parameter
value t or f. This transformation is called the t'-t transform. The t'-t transform is
only performed if the intersection point of the projected line segment and the cross
section has been identified. A detailed proof and discussion of the properties of the t'-t
transform are given in Appendix A . Important properties of the t'-t transformed are
51
summarized as follows:
1. if f = 0 then t=0,
4. dt/df > 0.
Because the First derivative dt/dt' is positive, the parameter t varies with the
parameter t* in the same direction (increasing or decreasing). Hence, the minimax values
tested with the side planes. The properties of the t'-t transform assure that the 3-D
5.3.1 Overview
1. transform the line segment to the local coordinates defined by the clip volume
(scene-to-local transformation),
2. find the visible segment confined within the hither and yon planes by determining
b. determine the visibility of the projected segment with the window polygon,
c. find their intersection points and project them back to the local coordinates
translating the clip volume is achieved by scaling, rotating and translating the line
primitives have the same shape within a particular type but only the sizes differ from
one to another. It is more convenient to normalize them such that "parallelepipeds are
all the same unit block in their local coordinate system, arbitrary elliptic cylinders are
all the same a right circular cylinder at the origin with unit radius and length, and
elliptic cones are all the same right circular cone with unit radius and unit length" in
a CSG-based system [Roth82]. For the sake of convenience, we assume ijf=0, z,y = l
in translational sweeping, and z # = £ Z y = l in conic sweeping where 0 < / < l such that
If the projected line L' intersects the window polygon P at w' then the line L
will intersect the corresponding side plane at w by the properties of the t'-t transform.
We can identify the position of the intersection point w if we know its projection w\
Let I F be the visible segment within the hither and yon planes. We project the
endpoints a and b onto the contour plane to yield the projected line segment jpb' (Fig.
5.3 and 5.4). Determine whether a^b' intersects with the window polygon P using either
the t-para method or the s-para method. If they intersect with each other then project
their intersection points back to the local coordinates using equation (5.3) or (5.7).
It should be noted that the 2 - D clipping algorithm does not actually find the
coordinates of the intersection points, but rather their t-para's that designate them. We
know, furthermore, that the line parameterizations are independent of coordinate systems
after the linear transformations between local and global coordinate systems. For example,
53
Fig. 5.3 Intersections with the side planes of a clip volume with translational
sweeping
Fig. 5.4 Intersections with the side planes of a clip volume with conic sweeping
54
the midpoint of a line segment is still the midpoint after the local-to-scene
transformation. This fact implies that step 4 in Section 5.3.1 can be eliminated when
utilizing t-para to designate the intersection point A formal description of the algorithm
is given in Algorithms 5.
55
Chapter 6
RECTANGULAR CLIPPING
In this chapter, a new rectangular clipping algorithm, called the mapping method,
will be presented. In rectangular clipping, the clipping boundaries (lines or planes) are
axis-aligned such that the clip window is a rectangle in 2 - D and the clip volume is a
to higher dimensions. We will describe the 2 - D rectangular clipping in detail and then
6.1 Introduction
input polygon. We can assume, without loss of generality, that the sides of the rectangle
are parallel to the x- and y-axes. The interior of the clip window is defined by two
pairs of parallel edges ( W ^ , W^) and (W^,, W ^ ) . The interior of the window can be
x. < x < x ff
L R
... (6.1)
H ~
y
* T
y
where x^, x^, y^, y^, are the x- and y-coordinates of the left, right, bottom, and
top of the window boundaries, respectively. The equal sign indicates that the points on
partitioning the 2-D space into nine regions as illustrated in Fig. 6.1. The shaded
region R g is the interior of the window. More formally, assuming u(u , x u^) is any
R
d
4 { u|(u <x ) J t L ,and. (y^<u ,<y ,) }> 7
R 4 {
e
R
/ 4 { u\(n >x )x R jmd. (y <u Zy )
B y T }
g
4 { u | ( x < u < x ) .and.
L ;t i? (u <y )
y B
or may straddle two or more of them. Depending on the relative locations of its two
endpoints, the segment may be entirely invisible (the line segment bypasses the window),
entirely visible (the line segment resides in the window), or partially visible (if the line
segment intersects the window at one point, it thrusts into the window; otherwise it
pierces the window). By convention 3, the line segment which has one endpoint
boundary is taken into account for intersection or is partially visible. For example, if
both endpoints of uv lie on a boundary, then it must be output to the clipped image.
In many cases the large majorities of line segments are either entirely invisible
whether a line segment is rejected or accepted for intersections for improving the
algorithm's efficiency. The classical line clipping algorithm due to Sutherland and Cohen
uses a four-bit code (outcode) to indicate which of nine regions contains the endpoint
of a line segment They utilize the logical "and" operation to reject those line segments
which lie entirely in one of the following four groups of blocks: (R , fl R^, R ),
c (R ,
Q
R
<3"
R
g^' ^ c'
R
R
/'
R
P' R
R
/ i ' P^ ee d e t a i l s o f
^ dgonthm i n
Chapter 5 of
significant amount of computation before rejecting those line segments which diagonally
bypass the window corner. To resolve this, Liang and Barsky introduced a technique
which computes a set of parametric values to fast reject line segments of this kind
rather than explicitly calculates the intersection points for each iteration in the
trivially reject invisible line segments for all cases. In the latter sections, we will analyse
the 2-D classifications first, then describe the mapping technique and pseudo window,
58
and discuss the t-para conditions for rejection. Finally, the 3-D version of the new
There are two approaches to solve the clipping problem: to solve individual cases
directly or to homogenize the problem, i.e. to formulize a set of cases and solve all in
a consistent manner. The first approach can be fast for particular cases but its
establish a new algorithm which runs fast for the large majority of classes and keeps
which are relevant to the intersection analysis (see Tables 6.1 and 6.2). In Table 6.1,
the number denotes the case number which corresponds to the regions in which the
endpoints of a line segment fall. Table 6.1 illustrates only half of the combinations due
to the symmetric property of the endpoints. The total number of combinations and the
percentage out of all combinations of each case are shown in Table 6.2. In addition,
examples of all cases are illustrated in Fig. 6.3. In cases 1 and 6.b, the line segment is
entirely invisible, while in case 2 it is entirely visible. There are two pairs of similar
classes (cases 3 and 4, cases 5 and 6.a) which are partially visible and are classified
depending on the simplicity to compute the coordinates of the intersection points. Case
6 is the most "complex class", because it needs further tests to determine whether the
It will be assumed that the number of line segments is asymptotically large and
that their endpoints are uniformly distributed at random in the 2-D space. The
probability V m n ° f a line segment whose endpoint falls into region m and the other
For the sake of simplicity, we can assume that the scene is mapped to Normal Device
Coordinates (NDC) prior to the clipping process so that the total area of 2 - D space is
1. In this case, all points are located in a square of unit size ( 1 X 1 ) and the area of
a subregion is less than 1. Although this asymptotic analysis shows the probability of all
classes for any arbitrary clip window, it is impractical since the probability P is not
definite; it varies depending on the window size and the relative location of the clip
region i h g i e d c D
a 6 1 6 4 1 1 1
b 6 ^5 6 6 3 6 1 1
c 1 6 6^1 4 6 1
d 6 6 1^ 5 ^ 3 1
e 4 3 4 3 2 ^
f 1 6 symmetry
g 1 1
h 1 1
i 1 case where one endpoint lies in region f
and the other lies in region g.
total 45 100.00%
window in the 2 - D space. Instead of using this analysis, we took the percentages out
of combinations shown in Table 6.2 as a quick projection for the occurrence of the
classified cases. Clearly, the mtrinsic nature of the scene greatly influences the
classification analysis. As an example, for fractal curves which consist of a large number
From Table 6.2, case 1 and case 6 are two large majorities which account for
44.44 and 31.11 percent of the combinations, respectively. Dealing with these special
cases, Sutherland and Cohen developed an elegant identification technique for case 1,
while Liang and Barsky developed a quick rejection algorithm for case 6. However, the
other cases were ignored. It should be noted that once the regions are identified to
which the endpoints of a line segment belong, cases 1 to 5 are trivial to solve,
especially for case 2. On the other hand, because case 6 is the worst case, a technique
First, a test is needed which determines conclusively to which class the line
segment belongs. Classifications can be achieved by identifying the regions of its two
2D - ( R 7 + R +R ), J J
where the subscript of the regions denotes the region code and 2D denotes the entire
2 - D space. Because of the symmetry of the regions, the region codes are simply 0, 1,
63.2 2 - D mapping
general and can be extended to higher dimensions. The region code can be easily
generated by two interval clipping operations where the endpoints of a line segment are
mapped onto the clipping window. Interval clipping is a 1 - D operation defined as:
YT
V B
X R
p(p ,x p^) be the mapped point of a point u ( u , u^). The 2 - D mapping simply
x
call IntervaLClip ( u ^ , y ^ , y ^ , 2, p N R ^ );
end;
The returned region codes are those illustrated in Fig. 6.2. If a point resides
outside the window, it will be projected onto the window boundary by the mapping
operation, otherwise it remains unchanged. The points within will be projected onto
addition, the points within R ^ will be projected into the corner vertex of the window,
while the points within R ^ remain unchanged. Utilizing the mapping technique, a line
segment can be classified by the region codes and/or the mapped points which
correspond to its endpoints (Fig. 6.3). Examples of mapped points are shown in Fig.
6.4.
2. The mapping eliminates all invisible' line segments and returns a shrunk image
window is shrunk to the window (Fig. 6.4(a)), while a polygon within the window
bypass and { . u * P = q * v ]
case i. 7
u#-—•
(trivially
rejected")
[u y
x
* py = q
x x
y x
x
Vy ] )
o r
c a s e 2. reside NR =NR =3 U V
case 3.
/u y thrust {NR = 3 and [ N R = 1 or 2 ])
U V
thrust { NR =3 and [ N R = 0 ] }
U v
(simple) or { NR =NRu=2 a n d p * q )
case 5. v x x
NRu*3 and N R * 3
6.b
V
6.a pierce
(complex) and {\$\< M<l«l>
c a s e 6. u
6.b bypass NRu*3 and N R * 3 V
the clip window, which will be discussed in the next section. We determine the
visibility of a line segment with the pseudo window rather with the clip window.
6.4.1 Definition
clip window formed by the diagonal resulting from the projection of the line segment
defined by (jp ,x q)
y and (q^, p^). Then, the pseudo window of uv is the rectangle
paqb (see Fig. 6.5). Both a and b he on the lines passing through p and parallel to
(a) (b)
o r i g i n a l endpoint. o mapped point. ® c o i n c i d i n g original
and mapped endpoint.
the x- and y-axes, respectively. Let m, a , j3 be the slopes of the straight line
containing the line segments uv, ua, ub, respectively. A slope comparison between a
and (5 satisfies a=/3 or a>/3^0 or O>0>a for all cases (see proof in Appendix B).
Let A x = v - u , &y=Vy-\i .
x x y As shown in Fig. 6.6, a set of t-para's are defined
for the entry boundaries and the exit boundaries of the pseudo window as follows:
exit: tqX = (q -u )
x x / Ax if Ax*0,
ty
q = (q -u )
y y I Ay if Ay*0.
Notice that the starting point is projected onto the entry boundaries and the terminating
point is projected onto the exit boundaries of the pseudo window (Le. the mapped
point p is on the entry boundaries and the mapped point q is on the exit boundaries
The entry and exit parameters have the form t=A/B. Dealing with the special
t= + ° ° 4
if (A>0 and- B=0), ^
t=-» if (A<0 ^ n d . B=0),
t , =0 if A=0,
y
entr
...(6.2)
t . =1 if A=0.
exit
The cases B = 0 are considered as if B is approaching G\. These rules are needed for
In fact, t is not necessary to be + » or - » but it must not be inclusive to [0,1], i.e. any
4
The case B=0 and A * 0 occurs if and only if the line segment is invisible such
that the line segment lies in the group of blocks ( R 0 > R^, R )
0 parallel to x-axis or
be eliminated if the line segments of this case are identified and rejected before
On the other hand, it should be noted that A = 0 occurs if and only if the
endpoint lies in the slabs confined by the extended infinite lines of edge pair ( W ^ ,
zero). In this case, assuming A x * 0 and Ay#0 (i.e. B#0) the parameters are as follows
68
(rejected)
tpx=0 since
since
since
since
The cases in (6.2) are a general case of this category, if we consider B=CV rather
than B=0. The equations in (6.2) become evident for both cases B*0 and B=0 from
this consideration. Note that the case where A=0 for exit boundaries occurs only when
u =\ =v =q
x x x x or u =\ =v =q .
y y y y Therefore, we have b =0
entry ,and. ^ e x H
= 1
) f o r
starting endpoint
69
(a) p= u
x x ; t x =0
p (b) Py = U y ; t y=0
p
termination endpoint
• •
(c) q = v ; t x = 1
x x q (d) q = vy:tqU = 1
y
the case A = 0 and B=0. This is different from the case A * 0 and B=0 in (6.1) giving
t . =t . = + » or
entry exit
Using the pseudo window, the visibility determination of a line segment against a
Lemma 5 If (t y£tpX
q ,and. t^x^y) 6
then the line segment uv is at least
5
This expression excludes the special case m=0=a.
'This expression excludes the special case (t y = t p X ,and. t x = tpy). q q
70
The proofs and a detailed discussion of both lemmas are given in Appendix C.
Lemma 5 is a variation of Lemma 4 using the entry/exit parameters rather than the
slopes. The pair of equalities in both Lemma 4 and Lemma 5 lead to uncertain results
for cases where m = a = /3. For normal cases when o*/3, the degenerate intersection may
occur when only one equality is satisfied (e.g. m=p\ |m|<|a|). In general, the t-para
comparison method is superior to the slope comparison method due to the fact that the
t-para's contribute to the coordinate calculation of the intersection points using Lemma
3.
almost all .cases, i t is still expensive because of the t • computation. To obtain a better
performance, cases which can be trivially rejected should be identified before applying
Lemma 5. The line segment which lies in the group of blocks (R^, R^, R^) or (R^,
Rj, RQ) can be easily rejected by knowing that the entry parameters t p X , t p y > l or the
exit parameters t q X , t y < 0 (i.e. the line segment does not reach the entry boundaries or
q
the line segment begins after the exit boundaries). By observation, this line segment is
either mapped into a clip window vertex or mapped onto a boundary of the clip
window (see Fig. 6.8). The trivial reject conditions are easily established as follows:
<and and.
x x x x
( Py=^ y Vy*u y q *v
y y )
The inequalities assure that the endpoints u and v do not lie in the interior of the
clip window including the boundary edges. These conditions are complicated for hardware
Sutherland-Cohen Algorithm can be applied here to form a simple circuitry. Recall that
the region code has two bits: a LSB (the first bit from the right) and a MSB (the
second bit from the right). If the boolean "or" result of the LSB's of NR and NR
is 1 then ( p * u x x and. q * v )
x x is false; otherwise true. Similarly, if the boolean "or"
otherwise true.
the x- and y-axes. The algorithm is a special case of the family t-para's clipping
algorithm. First, the endpoints are mapped to points p and q using the 2 - D mapping
technique. We use these mapped points, which lie on the window boundaries, to
compute the corresponding entry and exit parameter values ( t p X , tpy, t^x and t^y).
Although we can distinguish all classes using the region code and/or the mapped point's
coordinates (see Fig. 6.3 again) and handle them individually, it is not the best choice
t
t x=tqx g(0,1)
p
.or. t y = t y e (0,1)
p q
because an increase in the length of the algorithm decreases the average execution time.
Therefore, we divide the six classes into two groups: cases 1 and 2 and cases 3 to 6.
The former cases are trivially determined and the intersection coordinates need not be
computed. We generalize the other cases by using the entry t-para's and exit t-para's
to determine the visibility of the line segment based on Lemma 5 and using them to
At first glance, one might think the generalized version is slow to deal with the
simple intersection cases 3 and 5, where a visibility test is not necessary and the
appropriate coordinate (x- or y-) of the mapped points into the line equation y = f(x)
of uv. However, this approach is not adopted here by the reason mentioned above.
Because the parameter values can be initialized to zero or one, the t-computation is
skipped for the cases where the region code corresponding to u and v is not zero (see
Fig. 6.7 again). This saves some computations, while determining t values for cases 3, 4
and 5. By this formulization, the algorithm runs fast for case 1 and 2 and is compact
The proposed rectangular clipping algorithm is linear with the number of the
line segments to be clipped, since the clipping operation for each line segment runs in
constant time for the worst case. In order to explore parallel processing using the
mapping method, an execution tree of the algorithm is used. As shown in the Fig. 6.9,
pairs of operations are nicely linked in a pipeline. From Fig. 6.9, the regularity and
the simplicity of the algorithm also become obvious. The percentages of data flows are
adopted form our classification in Section 6.2 for an average analysis. The percentage of
73
interval-clip
of point u
interval-clip
of point v
t r i v i a l acceptance
parameters t
calculation
parameters t
calculation
coordinates
calculation
100.00X
note: i ) B l o c k s A and B, C and D can be implemented e i t h e r
in p a r a l l e l o r in pipelined f a s h i o n .
2) The percentages i n d i c a t e the p r o b a b i l i t i e s of
data f l o w s in T a b l e 6.2.
trivial acceptance and rejection are 2.22% and 44.44%, respectively. Assuming that half
the line segments of case 6 (15.55%) are rejected on the average, each t parameter
comparison rejects 7.77% of the total number of line segments. An important observation
is that nearly 60% of the line segments are rejected and that it is necessary to perform
additional inequality:
where z^ and Zy denotes the z-coordinate of the hither and yon planes. Similar to
the 2-D mapping, the mapped points p of u and the region code N R y are found by
The region code and its corresponding locations are illustrated in Fig. 6.10.
After finding the mapped points p and q of the endpoints of line segment uv,
the slope conditions are no longer suitable for determining intersections. However, if we
project the line segment down onto the x-y plane and the y - z plane, then the 3-D
orthogonal projections (see Fig. 6.11). Two sets of conditions for intersection are:
75
0 1 0 4
6„ center=?
1/1
4 5 4
0 1 0
z*
0 1/ 1/
Fig. 6.10 Region codes in 3 - D .
Fig. 6.11 Orthogonal projections of the clip volume and a line segment
76
t y>tpX, t x > t p y
q q (x-y plane)
and
t y>tpZ, t z > t p y
q q ( y - z plane)
where
A* = v -u ,
z z
tpZ = ( p - u ) / Az if Az#0,
z z
tz
q = ( q - u ) / Az if Az#0.
z z
Chapter 7
EXPERIMENTAL ESTIMATION O F
T H E EFFICIENCY O F T H E PROPOSED ALGORITHMS
7.1 Introduction
The clipping algorithms which were presented in Chapter 3, 4, and 6 have been
Electrical Engineering, the University of British Columbia. Since it seemed veTy difficult
for us to obtain theoretical estimates for the efficiency in the average case, we decided
to estimate the efficiency of our proposed algorithms with the conventional Liang-Barsky
1. The nature of the image that is to be clipped: for example, an image consisting
of fractal curves.
3. The relative size of the clip window with respect to the image, e.g. the area
over the 2 - D or 3 - D space. To simplify the experiments, we assume that the scene is
3 - D space which is defined in a N D C system, i.e. the coordinates are within the range
[0,1]. For the 2 - D generalized clipping algorithms, the clip window is a convex polygon
with equal sides of length; it approximates a circle as the number of sides grows. The
location of the center c of the clip window is located at (0.5,0.5). For rectangular
78
clipping, a square and a cube centered in the N D C space are used for the clip
The input to the algorithm are the coordinate arrays of the subject and clip
polygon vertices and its output is the coordinate array of the clipped polygon vertices.
The C P U times recorded in all experiments do not include the time to input the
subject and clip polygons, since we assume the data of those polygons are available in
storage. They do include, however, the time to setup the coordinates of the clipped
polygon vertices to the output array. For the 2-D generalized clipping algorithms, the
C P U times include both the preprocessing time and the search time of sector locations.
It should be pointed out that the C P U times vary a few percent as the program is
The sequential t-para method and the bisection s-para method are the two
implemented algorithms which we have used for efficiency estimations. They are simple
and efficient for clipping with a polygon of a large number of sides. Since the
bisection t-para method is very slow compared to these due to the expensive
efficiency evaluations. For example, in clipping 100 line segments to a clip window of
20 sides, the C P U time spent is 0.69 seconds for the bisection t-para method, while
only 0.31 seconds axe needed for the sequential t-para method.
Four categories of line segments are used for the efficiency evaluations:
1. Entirely visible: All line segments lie in the clip window and they are totally
output
2. Entirely invisible: All line segments are entirely invisible and no output is
79
generated.
3. Partially visible: All line segments have both endpoints outside the clip window
and the intersection points with the clip window are output This is a worst case
consideration: the line segments which intersect a clip window of 100 sides are
randomly generated as the test data. It should be pointed out that for the clip
window with small number of sides, e.g. triangular, a large fraction (22%) of the
line segments becomes invisible. However, the data are sufficient for testing the
clip windows with number of sides greater than 20 since the experimental results
showed that only 0.1% of the total number of line segments are invisible for
these windows.
We now show computational results of the experiments by varying the area ratio
of the clip window and using different categories of line segments outlined above. In
clipped and the C P U times vs. the number of sides of clip windows are shown in
Area ratio for the 2 - D generalized clipping is defined as the ratio of the area
of the circumscribed circle of the clip window to the 2 - D space of the N D C system.
The results of the experiments to clip 1000 line segments of normal case for the area
ratio 2, 10, 20, and 40 are shown in Fig. 7.1, 7.2, 7.3 and 7.4, respectively. The C P U
time for Liang-Barsky's algorithm is linear with the number of sides of the window
polygon, while the proposed methods (the sequential t-para and the bisection s-para
t-para and s-para methods run faster than Liang-Barsky's method when the number of
sides is large (greater than 50). It is observed that the execution time for the
Liang-Barsky algorithm reduces significantly when the area ratio increases (i.e. the clip
window becomes smaller), while the both new methods run comparatively in constant
time. As a result, the relative improvement of the new methods over the conventional
One of the most important observation is that the search time for the sectors
into which the endpoints fall accounts for a large portion (50% to 80%) of the total
execution time, while the actual clipping process requires very little time. Therefore, one
search. In fact, we simulated a recursive binary search by using a static array as stack
and calling two subroutines alternately. If the search time can be reduced by another
implementation, e.g. a specialized hardware, the new methods will run much faster.
Another observation is that if the area ratio increases, the bisection s-para
method becomes more efficient than the sequential t-para method (see Figs. 7.1 to 7.4).
It can be explained that if the window is small, there is less chance for line segments
to intersect with the clip window and thus most of line segments are invisible. Since
the bisection s-para method runs faster than the sequential t-para method for invisible
line segments but slower for partially visible line segments (as will be discussed below),
the former becomes superior to the latter for clip windows with a large area ratio.
VS.
N u m b e r of Sides
LEGEND
• Liang-Barskv
Bisection S-para
O _ Sequential. T-para
"b" Search lime
— o
VS.
u m b e r of Sides
LEGEND
• Liang-Barskv
Bisection S-para
o _ Sequential. T-para
"b" Search lime
o
cvj -I
VS.
N u m b e r of Sides
N o r m a l case: area r a t i o = 2 0
LEGEND
• Lian£-Barskv
Bisection S-para
O . Sequential. T-jDara
" 6 " Search time
o
oi —I -
VS.
u m b e r of Sides
LEGEND
• Liane-Barskv
Bisection S-para
o _ Sequential, T—.para
"b" Search time
o -©-
w -
i
20 40 60 80 100 120 140 160 180 200
Number of Sides of Window Polygon
Due to the fact that the inclusion test of a point against the clip window is
simple after the sector to which it belongs is known, the proposed methods run very
fast compared to the Liang-Barsky algorithm. It implies that the new methods are
efficient for clipping an image with a large window such that most of line segments
are entirely visible. It should be noted that this is a best case of consideration and the
In this case, the experimental results indicated that the bisection s-para method
show a slightly better performance than the sequential t-para method. The antipodal
point is found efficiently by the find-podal-point operation using the bisection technique
in Section 4.4, even though one might think the rejection test based on Lemma 2 is
effective and powerful in the sequential t-para method. In fact, this rejection test is
still efficient; as seen in Fig. 7.5, the Liang-Barsky runs fast for a large range (N=0
3. All segments are partially visible to the clip window of 100 sides (Fig. 7.7).
The results of this case are contrary to the previous experiment: the sequential
t-para method is somehow faster than the bisection s-para method. It can be explained
that the overhead caused by the halving operation is large. For the worst case, N/2 of
the boundaries are traced in sequence or a total of 2(log(N/4)) halving operations are
necessary to find both entry and exit points. Each halving operation consists of an
addition and a division of integers, it is not inexpensive. This causes the bisection
method to be less efficient in the software implementation. However, both new methods
surpass Liang-Barsky's method for the case where the number of sides is greater than
40.
86
In summary, the proposed methods run faster than the Liang-Barsky algorithm if
the number of sides is large. In general, the sequential t-para method shows better
performance than the bisection s-para method in our implementation. We combined the
experimental results of Figs. 7.6 and 7.7 into Fig. 7.8 and the results show that the
bisection s-para method is faster than the sequential t-para method when the number
of sides is greater than 120. Since convex polygons with large number of sides in
computer graphics applications are rare, the sequential t-para method is a good choice.
7.3.1 Overview
clipping algorithm can be implemented in parallel due to the fact that each line
segment or each parameter can be processed independently. Due to the iterative nature
parallel processing, e.g. in the supercomputers Cray-1, Cyber 205 and others, e.g. the
instruction can be performed on several data elements, yet only one instruction cycle is
processors have become available recently, called array processors (APs), which can be
attached as peripherals to conventional scalar processors. They are faster than scalar
processors and cost much less than supercomputers. The array processors can be
CPU T i m e *
VS.
Number of Sides
q
VS.
u m b e r of Sides
o
CD .
CVJ
A l l s e g m e n t s i n v i s i b l e : area r a t i o = 2
o
CO.
LEGEND
o • Liane-Barskv
Bisection S - p a r a
CO •
O _ Sequential. T—jgara
"6" Search " l i m e
VS.
umber of Sides
LEGEND
• Liane-Barskv
A
Bisection S-nara
O _ ]3equential_ T-jJara
b" Search time
o
cvi -
VS.
N u m b e r of Sides
o
d .
LEGEND
o • Lian£-Barskv
A
CD •
Bisection S-nara
O . S_e_quentia_l. T-para
O
~b~ Search lime
controlled by the host computer to execute the routines requiring repetitive operations,
e.g. vector arithmetic and logical operations, while scalar operations still take place in
array processor FPS-100 which is connected to the host V A X computer. Since the AP
executes the operations in a pipelined manner, it is efficient for processing a large data
array. Furthermore, it is more efficient to force the whole array to perform the same
operation rather than to distinguish a small portion of the array to perform a specified
task. This indicates that one of the best ways to exploit vectorization is to homogenize
the problem, eliminating as many special cases as posssible. Therefore, the special
treatment for the trivial rejection (case 1) and the trivial acceptance (case 2) in
minimax value searching of the t parameters like the Liang-Barsky method is suitable
to vectorization. The coordinate calculation of all valid and invalid intersection points is
performed in the AP. Despite the fact that the vector version requires more arithmetic
computations than its scalar counterpart, the actual execution time can be less.
and conditional branching. For example, addition of two vectors A and B, with the
results stored in vector C, all vectors with N elements, is written in vector code of a
92
On the other hand, the AP offers a mathematics library which contains a large
number of subroutines for vector/matrix arithmetic and vector logical operations [Apma].
The same vector codes of a FPS-100 for the previous examples are:
From this example , we know the difficulty to convert a scalar code into a vector code
for the branching conditions in the AP. It implies that we should eliminate as many
Unlike the conventional scalar processors, the AP does not abort a job when an
arithmetical error occurs. For example, while the scalar processor is interrupted when
answer. Table 7.1 shows the division results when using the AP as follows:
93
A B t=A/B
1. *0 *0 A/B
2. >0 =0 + 00
3. <0 =0 —CD
4. =0 *0 0
5. =0 =0 0
Except for case 5 in Table 7.1 the results of all cases agree with rules (6.1) and (6.2).
For case 5, the division result is zero for entry parameters t p X or tpy but it is 1 for
tqX and t^y. Therefore, a special treatment is needed which converts t q X and t y to 1 q
Note that all the data are input into the A P before processing begins and all
results are returned to the host computer after processing ends. The run time of an AP
is the sum of the I/O time and computation time. To save the I/O time, the AP
must store intermediate results in the AP memory for later use. The memory for
intermediate results grows fast according to the amount of the input data. The required
space is not insignificant In the rectangular clipping algorithm, the memory requirement
for the intersection test and coordinate calculation is 5nM (words), where n is the
dimensions and M is the number of line segments to be clipped. Since the FPS-100
has 64K words of main memory in our configuration, it was estimated that a maximum
of 6540 and 4360 line segments can be vectorized for 2 - D and 3 - D rectangular
clipping, respectively. Note that in the FPS-100, a word is 38-bits long including a
The experimental results of 2-D and 3-D rectangular clipping are shown in
Figs. 7.9 to 7.17. First, the linear complexities of the implemented algorithms: the
Liang-Barsky algorithm, the scalar version and the vector version of the mapping
method, are confirmed in Figs. 7.9 to 7.14. Three groups of the clip window/volume
were tested: small, medium, and large. In each group, four sizes of the clip
window/volume were used. The area (resp. volume) ratio is defined as the area (resp.
volume) ratio of the clip window (resp. clip volume) to the NDC 2-D (resp. 3-D)
space. If the ratio increases, the clip window/volume reduces its size compared to the
scene.
compared to the medium and small clip windows/volumes (see Figs. 7.15 and 7.16). The
large improvement was obtained by the trivial acceptance condition in which the region
codes of the endpoints are tested instead of computing t parameters. On the average,
the scalar version and the vector version of the mapping algorithm showed a 36 percent
percent improvement for 3-D clipping, respectively. The decrease in efficiency for the
3-D mapping algorithm is caused by the overhead of the mapping operation for the
trivially rejected line segments. Since the trivial reject conditions can be tested in pairs
with the boundary mapping in sequence, the performance will be improved by this
modified version. The improvements of the mapping method over the Liang-Barsky
In the vectorization, if the number of line segments is very large so that the
58 percent has been gained for 2-D and 3 - D clipping. An interesting observation is
that the improvements of the 2-D and 3-D version showed a similar characteristic
against the number of line segments to be clipped (Fig. 7.17) The improvement
increases (assuming the AP has sufficient memory). This implies that more APs running
N u m b e r of L i n e Segments
o
Area Ratio
c\i •
• = 1.0 x = 4.0 * = 25.0
o = 1.5 o = 6.0 * = 50.0
A
= 2.0 v = 10.0 © = 100.0
4
= 2.5 a = 15.0 s = 200.0
in Area Ratio
c\i • • = 1.0 x = 4.0 * = 25.0
0
= 1.5 0 = 6.0 * = 50.0
A = 2.0 v = 10.0 e = 100.0
+
= 2.5 H = 15.0 " = 200.0
VS.
N u m b e r of Line Segments
o
in A r e a Ratio
c\i- • = 1.0 x = 4.0 * = 25.0
o = 1.5 o = 6.0 * = 50.0
A — 2.0 v = 10.0 © = 100.0
+ = 2.5 a = 15.0 " = 200.0
Volume Ratio
• = 1.0 x = 10.0 * = 100.0
0
= 1.5 o = 20.0 * = 160.0
A
= 2.0 * = 40.0 © = 200.0
4
= 5.0 a = 60.0 = = 400.0
u m b e r of Line Segments
o
co •
in Volume Ratio
• = 1.0 x = IO.O * = 100.0
o = 1.5 o = 20.0 * = 160.0
A = 2.0 v = 40.0 ffi = 200.0
+ = 5.0 H = 60.0 a = 400.0
N u m b e r of Line Segments
3 - D m a p p i n g m e t h o d : vector version
Volume Ratio
• = 1.0 * = 10.0 x = 100.0
o = 1.5 o = 20.0 • = 160.0
A
= 2.0 * = 40.0 © = 200.0
•+
= 5.0 a = 60.0 a = 400.0
Area Ratio
1 1 1
Pro posed 2-D rect angu lar c lippii ig alj>oritll m
LEGEND
• Scalar Version
A Vector Version: average
0)
o Vector Version: max
CU)
i
«>
k
0*
A 4 «,
CD
E
O
11
OH
£
Area Ratio
Fig. 7.15 Improvements of the 2 - D mapping method vs. area ratio.
Improvement Percentage 103
VS.
V o l u m e Ratio
1 1
Proposed 3 - D rect angullar c] ippir ig al|>oritrl m
LEGEND
• Scalar Version
A Vector Version: average
o Vector Version: max
CD
1
i,
«•
OH """"-•< « K
4>
CD
£
O
)
u
1 i I
20 40 60 80 100 120 140 160 180 200
Volume Ratio
VS.
u m b e r of Line Segments
o
Vector version of rectangular clipping
b.
05
o
d .
LEGEND
CD
D 2 - D Clipping
A 3 - D Clipping
Chapter 8
CONCLUSIONS
8.1 Summary
The intersection problem of a line segment with a convex object has been
studied. First, to solve the 2-D generalized line clipping problem, two families of
parametric clipping algorithms have been proposed: the t-para method and the s-para
method. Both methods can be implemented using the sequential tracing or numerical
respectively. The parallel executability of these methods has also been examined. As an
extension, a 3-D clipping against a sweep-generated object has been discussed. Using
this technique, a truncated pyramid, which. is often used in the viewing transformation,
can be applied as a clip volume. However, the clipping for homogeneous coordinate
Secondly, to deal with rectangular clipping where the boundaries are axes-aligned,
a mapping method was proposed to test the visibility of a line segment with the
so-called pseudo window rather with the actual clip window. A set of rejection
conditions (Lemma 4 and Lemma 5) has been established. The possible parallel
processing and the regularity of the 2 - D rectangular clipping algorithm is shown by the
execution tree.
Finally, the sequential t-para and the bisection s-para methods have been
implemented and their practical efficiency has been evaluated by comparison with the
Liang-Barsky algorithm by varying the area ratio or clipping different categories of line
segments. For the rectangular clipping methods, a scalar version and a vector version
106
have been implemented. The vectorization technique on an array processor has been
applied to implement the vector version. Practial experiments have been performed to
estimate the performance of the scalar and vector versions with different sizes of clip
The computational experiments showed that the sequential t-para method and the
bisection s-para method seem to be practical for clipping with a convex polygon of
number of sides greater than 40. The number of sides can be smaller if the search
time of sector location is reduced. The bisection s-para method is efficient when the
For rectangular clipping, the scalar and vector version of the mapping method
improvement for 3-D, respectively. The vectorization of the clipping algorithm can take
possible which deal with the clipping problem for which a non- convex polygon is used
for the clip window. First, if the clip window is a star-shaped polygon P, we choose
an interior point c located in its kernel (a collection of points which can see all
interior points of P) so that the uniqueness of the sector belonging to an arbitary point
is assured by the properties of the kernel. Then the visibility of a line segment can be
longer effective for trivial rejections, the s-para method should be used because of the
less expensive G or F computation. The second approach is to find the convex hull of
an image (a concave polygon), then the intersection problem of a line segment with the
convex hull can be solved by using the parametric clipping algorithms. If it is possible
to find the intervening edge chain of the visible line segment with the convex hull, a
A fast clipper can be obtained by conbining both the generalized and the
rectangular clipping algorithms. We first clip the image with the circumscribed rectangle
of the clip polygon. The invisible segments are easily rejected and a generalized clipping
algorithm can be used to detect the visibility of the line segments within the rectangle
using VLSI technology deserves future attention. Finally, the vectorization of the t-para
BIBLIOGRAPHY
[Ahuj80] Ahuja, N . , R.T. Chien, R. Yen, and N . Bridwell, "Interference Detection and
Collision Avoidance among Three Dimensional Objects," Proc. of First Annual
National Conf. on Artificial Intelligence, Stanford, C A . , 1980, pp. 44-48.
[Apma] APMATH38, AP Math Library Manual, Floating Point Systems Inc., July
1982.
[Boys79] Boyse, J.W., "Interference Detection Among Solids and Surfaces," Comm.
ACM, 22(1), Jan. 1979, pp. 3-9.
[Chaz80] Chazelle, B. and D.P. Dobkin, "Detection is Easier than Computation," Proc.
of the Twelfth Annual ACM Symp. on Theory of Computing, Los Angeles,
1980, pp. 164-153.
[Clar80] Clark, J.H., " A VLSI Geometry Processor for Graphics," IEEE Computer
13(7), July 1980, pp. 59-68.
[Gera] Gerald, C.F., Applied Numerical Analysis, 2nd. Ed., Addison-Wesley, N.Y.,
1983.
109
[Kaji83] Kajiya, J.T., "New Techniques for Ray Tracing Procedurally Defined Objects,"
Comput. Graphics (Proc. Siggraph '83), 17(3), July 1983, pp. 91-102.
[Lian83] Liang, Y . - D . and B.A. Barsky, " A n Analysis and Algorithm for Polygon
Clipping," Comm. ACM, 3(1), 1983, pp. 868-877.
[Lian84] Liang, Y . - D . and B.A, Barsky, " A New Concept and Method for Line
Clipping," ACM Trans. Graphics, 3(1), 1984, pp. 1-22.
[Mehl84] Mehl, M . E and S.J. Noll, " A VLSI Support for G K S , " IEEE Comput.
Graphics and Appl., 4(8), August 1984, pp. 52-55.
[Pavl] Pavlidis, T., Algorithms for Graphics and Image Processing, Computer Science
Press, Rockville, M d , 1982.
[Roth82] Roth, S.D., "Ray Casting for Modeling Solids," Comput. Graphics and Image
Process., 18(2), Feb. 1982, pp. 109-144.
[Sham75] Shamos, M.I., "Geometric Complexity," Proc. of the Seventh Annual ACM
Symp. on Theory of Computing, 1975, pp. 224-233.
[Spro68] Sproull, R.F. and I.E Sutherland, " A Clipping Divider," AFIPS Conf Proc.
Vol. 33, 1968 F J C C , pp. 765-775.
[Suth74] Sutherland, I.E., R.F. Sproull and R.A. Shumacker, " A Characterization of
Ten Hidden Surface Algorithms," ACM Computing Surveys, 6(1), March
1974, pp. 1-55.
[Tran84] Tran, C.H., " A n Implementation of an Algorithm for Array Processing: Curve
and Surface Definition with Q-Splines," E L E C 593 course project report,
Department of Electrical Engineering, the University of British Columbia,
June 1984.
[Weil77] Weiler, K. and P. Atherton, "Hidden Surface Removal using Polygon Area
Sorting," Computer Graphics (Proc. Siggraph '77), 11(2), Summer 1977, pp.
214-222.
[Wijk84] van Wijk, J.J., "Ray Tracing Objects Defined by Sweeping Planar Cubic
Splines," ACM Trans. Graphics, 3(3), July 1984, pp. 223-235.
[Zago83] Zogorsky, J., "Real Time Graphics with an Array Processors," Digital Design,
April 1983, pp. 51-55.
Ill
APPENDIX A
The parameters t and t' designate the point w and w' where w lies on the
infinite line L containing uv and w' lies on the infinite line L\ the projection of L
onto the contour plane with the translational or conic sweeping defined in Section 5.2.2
and 5.2.3. The t and t' relationship is shown in Equations (5.3) and (5.7), respectively.
1. Assumption
We assume that both endpoints are visible to the hither and yon planes due to
the fact that the segment which straddles either/both of the hither and yon planes can
the case where the segment is invisible but is projected onto the contour plane
and v >0.
z
2. Translational sweeping
By Equation (5.3), the relationship between the parameters t and t' for
translational sweeping is simply t=t\ Then the properties of the t-t' transform is
2. if t' = l then t = l ,
The third property assures the point w lies on the line segment uv, if its
projected point w' lies on the projected line segment Irv.' Because the first derivative
112
(dt/dt') is positive, if t' increases (resp. decreases) then t increases (resp. decreases)
accordingly. Thus, if f is the minimax value for the 2-D entry/exit point of the
projected segment u V with the window polygon P, then the corresponding t designates
the minimax value for the 3-D entry/exit point of the original segment uv with the
3. Conic sweeping
Let point w' be the "valid" intersection point of line segment uv and window
polygon P in the contour plane. The parameter t designating point w can be computed
t = ... (5.6)
This equation is not valid for the case v = u Y and v =u . In this case, however, if
v *u
z z then the parameter t can be computed by t^= (w ~u )/(v -u );
z z z z otherwise, no
t computation is needed because point u and v coincide (see Fig. A.1). Note that in
the former case w = u z /w' v = v u„z /w' v if w' * 0 and w' * 0; otherwise, the
z x Y x y Y y x y
line segment uv is parallel or collinear to ow' and point w' is an invalid intersection.
By substituting w' = ( l - ? ) \ i / u
x x z + t'v^/v.,, w'^= ( l - t ' ) u ^ / u z + t'v / v z into
the right side of Equation (5.6) and assuming u > 0 and v >0, we have
z z
t = A / B,
where
A = u ,[(l-t')u /u
J JC z +fv /v ]--
x 2 u [(l-t')u ,/u +
x > z t'vyv ] z
= ( *V *V v u t , / v
z-
B = (V^UjUl-VUy/^+t'Vy/Vj - (Wy-Uy)[(l-OU /U + x z t'W^V^
113
t = ... (5.7)
v (l-f)
z + u t'
z
Equation (5.7) denotes the correspondence between parameters t and t'. It causes
to ow' as shown in Fig. A.2. By assumption u > 0 and v >0, the parameter value t' is z z
greater than one if v > u , z z otherwise less than zero. In both cases, point w' is not a
valid intersection point and, therefore, the t-t' transform (5.7) is not performed.
In summary, both Equations (5.6) and (5.7) can be used for the t-w' or t-t'
transform once the "valid" intersection point w' is identified, except that a special
treatment is needed for (5.6) when uv is parallel to z-axis. In the implementation, only
2. if t' = l then t = l ,
Proof. By assumption u > 0 and v >0, the numerator and the denominator of the
z z
right side of Equation (5.7) are greater than or equal to zero. So we have teO.
t = 1 / [ v (l-t')/u t' • +
z z 1 ].
4. if u = v
z z then t=t' (equivalent to translational sweeping),
5. dt/dt* > 0.
114
dt _ u [(u -v )t' + v ]
z z z z - (u -v )u f
2 z z
dt' [(u -v )f
z z + v ] z
2
u
z z v
[(u -v )f
z z + v ] z
2
intersection point w' designates the entry/exit point of line segment uv with the side
Z=Zy 1 v'
w' u"
w - "2
t =
z
vz - u z
where w =u zy/ w' z x x
= u z / Wy
y Y
x or y
V" u"
Z=Z Y
•1 \ • /
••t
•• •. /
• / J
v• t
X/
y
•
• // u
:
• x or y
APPENDIX B
Given a line segment defined by two endpoints u(u_ , u^) x and v(v , x \ ).
y Using
respectively. The pseudo window defined by the diagonal pq has other vertices aCp^.,
q )
v and b(q , p ) r v such that pa is vertical and pb* is horizontal. We assume that the
y *• y
vertical line has positive/negative infinite slope and the horizontal line has zero slope by
convention. Here, we intend to prove that a,/3 have the same sign and |a|^||3| is
valid for all cases, where a and 0 aie the slopes of the lines containing the segment
ua and ub respectively.
Proof.
in Fig. B. It is necessary to classify and verify all cases for values a and /3.
horizontal positive vector if Ax>0, otherwise negative. The slope comparisons are based
In this case, because p=u thus ua=pa (vertical) and uF=pF (horizontal),
slope(ua)>slope(uH)^0 or a>/3^0.
This case occurs when both u and v lie on the left of W ^ , on the right of
except that pF or pa is a null vector because Ax' = 0 or Ay'=0. The slope comparisons
These special cases occur either in case 3.a: when p=q (Ax' = 0 and Ay'=0) or
in cases 3.b and 3.c: when pq is vertical (Ax' = 0) or horizontal (Ay' = 0). In both cases
ua and uF coincide with each other, hence a=P is easily found (see Fig. B).
above. The inequalities can be combined into the simple form a * 0 ^ 0 and |a|^|/J| for
all cases.
Q.E.D
118
iA Q (cose l.o) NR =3
U
|oc| > 1 ^ |
Note: Ax = v - u
q«a C v (cose 3.0) x
A y = Vy - Uy
x
'a Ax=0,Ay=0:
a = £ ^ m.
Ax'= q - p
Ay"= q - P
x
y y
x
APPENDIX C
Lemma 4: If a,/3,m have the same sign and |a|>|m|^|/3|\ then the line segment uv
Here m, a , 0 are the slopes of the straight line containing the line segments uv, ua
Proof.
From Appendix B, we know that a* 0^0 and |a|^|/3| is valid for all cases.
Ignoring the special case a=/3, let us consider the angle 6 defined by two vectors ua
and ub". It is clear that if the vector uv lies in the sector with angle 6 (i.e. m«a>0
and |a|^|m|^|/3|), it must intersect the pseudo window and intersect the clip window as
a consequence. In fact because the endponts u and v are located in diagonally opposite
regions (see Fig. B cases La to I.e), the line segment uv must reside in or intersect
with the pseudo window. On the other hand, if the vector uv lies in the outside the
sector with the angle 6 (i.e. m « a < 0 or { m « a > 0 and (|m|>|a| or |m|<|/3|)} ), then
no intersections occur. In this case, the line segment is exterior to the pseudo window
and consequently it is invisible to the clip window. All classes (as defined in Table 6.2)
entirely invisible (see Case 3.a in Fig. B). However, m=a=/3 implies that the line L
containing uv passes through the points p and q which does not guarantee that uv
intersects the clipping window (see Cases 3.b and 3.c in Fig. B). Thus, the condition
m=a=/3 is not a sufficient condition for intersection testing. This case must be treated
separately.
Q.E.D
visible to the clip window; otherwise, entirely invisible, except that the case
Proof.
accepted for intersections if a,/3,m have the same sign and |a|£|m|>|0|. Notice that
m = Ay / Ax,
a = fy-iip / (jp -u ),
x x
P = (Vy-u ) y i (q -u )
x x
Ay
> > ... (C.1)
Vx~ x u Ax
>
Ay Ax
Vy-»y
>
Ax Ay
then we have
m*oc=£ u
(rejected) case 1 case 2
m=a=£(rejected) l«| 2|m|> |£|
accepted.
a>£>m
(rejected)
£( accepted)
case 3 case 4
M2|m|2|£l W2|m|>|^l
accepted. accepted.
v.
" ' M * M * | * | .
122
and
I V I* Iy | ... (C.3)
Iv * V 1 1 1
... (C.4)
( t y^tpx and. y^y
q )
The inequalities in (C.4) are verified for all cases: if the line segment is partially
visible (intersect) or entirely visible (reside) to the clip window, then the inequalities are
• Case p*q:
We know all the t-parameters must be within the range [0,1] for the
intersect or reside cases (see Fig. C.2a). Since both left and right sides of
t x<0
q (resp. t p X > l ) leads to contradict t x £ t p V q (resp. t y ^ t p X ) .
q The same
argument can be applied to the line segment lying in the group of blocks
(R , 0 R , ; R ). 0
or t x#tpy
q for the reject case ( m * a = / J ) . Assuming (C.4) is true for the
contradicts t y=tpy. q
123
tpX = t q X = + ° ° or - » (see Section 6.4.2 for details). To simplify the discussion, only +°>
value is used.
The line segment resides in or intersect with the window, the mapped point
p and q must lie within the segment uv given t^y, tqy e[0,l]. This leads
t y^
q t^x and t x> t^y
q by knowing tpX=0 and tqX=l.
The line segment lies outside the clip window. We have t p X = t q X = + = > and
vertically. In this case if the mapped point lies ahead uv then tpy>l
tqy^tpX is false.
The discussion on the case Ay = 0 is omitted because of its analogy to the case Ax=0.
In summary, we have proved that the conditions tqy^ t p X and t q X > tpy determine
the visibility of line segments for all cases except that (tqy = t p X ,and. t q X = t p y ) yield
uncertain results.
Q.E.D.
3
The case A x = A y = 0 is not considered here.
124
Discussion
for intersections. Note that range checking of these t-para's is eliminated (the major
merit of this method), because for the visible cases they are explicitly inclusive to [0,1]
property as the line segment crosses the window boundaries: if the line segment is
Then, all these properties and the inequalities in (C.4) satisfy the conditions in Lemma
2. Lemma 5 provides an efficient testing which can reject a diagonally bypassing line
segment with only two evaluations of t for the best case, while Lemma 2 needs at
by range checking: if p = ae[0,l} then max_tO=min_tl e[0,l] and uv touches the clip
window at a point, otherwise uv is invisible (see Fig. C.4). However, we are trying not
to test the t-para's with the range [0,1] as in the Cyrus-Beck and the Liang-Barsky
algorithms but to fully use the properties of the 2 - D mapping. In fact, we trivially
reject the invisible line segments of this case before applying Lemma 5 by using other
a q
Ax>0,Ay>0 Ax<0,Ay<0
tpx,tqxe[0,1] d
t x,tqxe[o,1]
p
h t p y , t y e[o,1]
q
tpy,t y e [ o j ]
q
tpX,tqXE[o,1] * t x,tqXE[o,1]
p
la q
Note: Ax = v - u
x x
Ay = V y - U y
tpx=tqx<0
t y,t y e [ 0 J ]
p q tpx=t x>i q
t y , t y e[o,H
p q
p=<* e[o,i] t q y * t x or
p
u
(rejected) tqxxtpy
note:
(rejected)
tqy=t x=pp
tqx=t y=ap
p=tf e [0,1]
(accepted)
tpx=tqx=+oo t. I tqx<t y p
tpy=tqy^[Ojr" (rejected)
(rejected)
Note: Ax = v x
Ay = v y
tqy=t x=0
p
tpy=tqx=1
(accepted)
(accepted)
Ax=0
t p y = t q X = 0 (accepted)
V Y
t q y < t x or
p
t q y=tp X= 1 (accepted)
t x<t y
q p -
tpy=t y=+oo
q
(rejected)
tpx=tqxg[0,1]
(rejected)
Ay=o
tpy,t q y G [0,1],
tpx=0, tqx=1.
- 4 + —
.../IT® ®
tpx =tq x =+oo
tpy,tqye[o,l]
u
Ax=0
tpx,t xe
q [o,1],
tpy=0, t y = 1 .
q '*
®—®
l
py =tqy=+oo^
final i l
mi3x_tO miri_t1 1
1
•
mex_tO=max ( t x , t y ) p p
p = q and max_tO=min_t1 •
APPENDIX D
LISTING O F A L G O R I T H M S
Algorithm Page
begin
1. initialization
visible(uv,Lj)=true, t0=0, tl=l;
2. compute E (i) and E (i)
u v
E (i)= fii'U
u
E (i)=£rv
v
3. determine the visibility of the line segment uv with respect to the boundary Lj.
else
tO = t (i) uv
{ entry point }
endif
else
if .noi. interior (u, Lj) then
visible(uv, Lj)=false { entirely invisible }
else { entirely visible }
endif
endif
E (i)=fii«u, E (i)=e. v;
u v
r
3. determine the visibility of the line segment uv with respect to the boundary Lj.
if E (i)<E (i)
u v
then { B (i)>0 } uv
if E (i)<E(i)
v
then { cross=false: E (i)<E (i)<E(i) u v
{ partially visible
tO = (E(i)-E (i)) / (E (i)-E (i))
u v u
{ entirely visible
endif
endif { end of entry or parallel boundary }
else { E (i)<E (i) or B (i)<0 v u uv
if E (i)<E(i)
u
then { A (i)>0: E (i)<E (i)<E(i)u v u
{ partially visible
tl = (E(i)-E (i))/ (E (i)-E (i))
u v u
{ entirely visible
endif
endif { end of exit boundary }
endif { end of all cases }
end; { end of procedure Line-Visible }
Algorittaa 3.3
Procedure T-clip (u,v; var max_tO, mintl, accept)
{ function: this procedure outlines the t-para clipping algorithms,
input the endpoints u(u ,u ) and v(v ,v ).
x v x v
case of G c
<0: incr = +1
>0: incr = -1
=0: goto 5
endcase
4.2 tracing process
call T-sequential (u,v,incr4c,l,u_interior,v_interior,
max_tO,min_tl, accept)
or
call T-bisection ( u,v,incr,k,l,u_interior,v_interior,
max_tO,min_t 1 .accept)
endif;
end; { end of procedure T-clip }
Algoriilhim 3.4 a
Procedure Trace-boundary (u,v4; var maxtO, min_tl,accept,terminate)
{ function: this procedure tests the visibility of a line segment uv w.r.L an entry or
parallel boundary Lj.
input: the endpoints u(u ,u ) and v(v ,v ); maxtO, min_tl.
x v x v
begin
1. compute E (i) = £j • u ; u
if E (i)<E(i)
v
then { cross is false: entirely invisible }
accept = false
else
t (i) = (E(i)-E (i)) / (E (i)-E (i))
uv u v u
if t (i)>min_tl then
uv
{ ^ntry^xit )
accept = false
if t (i)<max_tO then
uv
{ t-para: decreasing or equal }
terminate = true
else { t-para: increasing }
max_tD = t (i) uv
endif
endif
endif
endif
accept=false
else
m=mid-mcr, t =t (m), entry_term=true { range [k,mid-incr] }
m
uv
endif
n
goto 3
endif
t (mid)= A (mid) / B (mid)
uv u uv
endif
1.2 shifting exit boundaries
if B (mid)<0 .and- exit_term then
uv
endif
1.3 halving iteration
midl=mid+incr
compute B (midl), A (midl)
uv u
accept=false
else
m=mid, t =t (mid), entry_term=true { range [k,mid] }
m
uv
endif
goto 3
endif
t (midl)= A (midl) / B (midl)
uv u uv
if t (mid)<t (midl)
uv uv
then { t-para turns to decreasing }
if B (mid)>0 .and. t (mid)% then
uv uv
else
if B (mid)<0 .and. t (midl)<t then
uv uv
k
else
accept=false
endif
endif
endif
endif
endwhile
end; { end of procedure Find_range }
AJgorittam 3.5 b
Procedure Find_max_t (u,v; vark.m, t^,^, )
{ function: this procedure bisectionally finds the maximum value of t-para
within the entry range [k,m] containing the hill,
input: endpoints u(u ,u ) and v(v ,v ); the range [k,m] with [t^t^].
x y x y
output the updated range [k,m] with [tj ,t l and the maximum value t^^-
c m
maxtfound = false
while .not. max_t_found then
case of
1. m-k>2:
mid = (k+m)/2 , compute t^a=tuv(mid)
midl = mid + 1, compute tj^^^t^midl)
i f
WdPWd t n e n
i ^P increasing }
30
k=mid, t =t k mid
else
tmidl^d
i f
('"P " deceasing }
t h e n 8 1
m=midl, t ^ t ^ !
else {equal t-para }
Wx rnid> max_t_found=true
=t
endif
endif
2. m-k=l: { neighbouring edges }
t =max(t ,t ), max_t_found=true
max k m
endcase
endwhile
end; { end of procedure Find_max_t }
Algorithm 3.5 c
Procedure T_bisection ( u,v, incr,
~ var k,l, t^.tp max_tO,min_tl .entry_term, exit_term,accept)
{ function: this procedure bisectionally finds the minimax values of t-para
within the range [k,l] of the intervening chain,
input: endpoints u(u ,u ) and v(v ,v ), the range [k,l] with [t^,t ] and incr;
x v x y 1
begin
1. find ranges containing the hill and/or the dale of t-para.
call Find_range (u,v,incr, k, 1 , 1 ^ , m.n.tju.tjj, entryJerm,exit_term,accept)
2. find minimax values of the t-para if accept=true.
if accept then
if .not. entry_term then { find entry point if u is not interior to P }
if m>k then
call F i n d m a x t (u,v, k,m, t^, maxtO)
else
call Find_max_t (u,v, m,k, t ^ t^, max_tO)
endif
endif
if .nd. exit_term then { find exit point if v is not interior to P }
if l>n then
call Find_max_t (v,u, n,l, l-t^ l - t max_qO)
l t
else
call Find_max_t (v,u, 1A l-t lP l-t„, maxqO)
endif
min_tl = 1 - max_qO
endif
if inax_tO>min_tl then { check reject conditions }
accept=false
endif
endif
{ function: this procedure performs a binary search within the range [a,b] to find
the intersection point of segment uv and polygon P.
input: range [a,b], incr and the F_parameters F , F and Fg. a b
begin
1. if F =Fa then g
{ w liesonL }
a
z=w, goto 6 a
endif;
2. if F =F5 g then { waliesonL }
z=w , b goto 6
endif;
3. initialization
term=false
4. while b*a+/ncr .and, term then
i=(a+b)/2, Fpn-Wj;
case of (Fg-Fj)incr
<0: a=i, F =Fj a
{ Gj G >0 }
c
endcase;
endwhile;
5. compute the coordinates of the intersection point
ab = ( g - a ) ( b - a ) ;
s F F / F F
z = w + s (w -w );
a ab b a
begin
1. if u_interior .and. v_interior then
z=u, w=v, accept=true,
goto 6
endif;
2. initialization
accept=true, term=false,
find the starting and ending vertices of the intervening chain
if incr=+l then
a=k, b=l+incr
else
&=k-incr, b=l
endif;
F =I2u; F = D w , F =J2 w ;
g a a b b
goto 6
endif;
4. if v_interior then { v is interior to P }
call Find__Intersect (a, b, incr, F , F , F , z), a b g
w=u,
goto 6
endif;
5. worst case : w and w lie on the same half plane of c w.r.t L
a b
term=true
endif
endwhile
6. end; { end of procedure S_bisection }
141
AlgorittaBi 5
begin
1. initialization
accept=true, max_tO=0, min_tl=l;
2. scenetolocal transformation
(u , Uy, u , 1) = (U , U , U , 1) • M
x z x y z
(v ,v ,v ,l) = ( V , V , V , l ) M
x y z x y z
Find the visible segment ceaoeb w.r.t. the hither and yon planes
{ The detail of this procedure is not shown }
call Intersect_Hither_Yon (u, v, a, b, accept)
if .JM- accept then goto 7 endif;
project the segment ceaoeb onto the contour plane
case of CI
0: a' = a, b' = b; { translational sweep}
1: a* = a/a , b'= b/b ;
z {conic sweep } z
endcase
5. 2_D clipping of the segment aV with the clip window
call 2D_CHp (a , b\P, max_tO', min_tl', accept)
1
endcase;
6.2 compute the coordinates of the entry point and exit point
if max t0=0 then
Z = Tj
else
Z = U + max_tO (V - U)
endif;
if min tl=l then
vr=v
else
W = U + min_tl (V-U)
endif;
end; { end of procedure 3D_clip }
Algorithm 6
Procedure 2D_Clip (u,v; var max_tO, miri_tl, z, w, accept)
{ function: ~ this procedure clips a line segment uv against a rectangular window,
input the endpoints u(u ,u ) and v(v ,v ). x v x v
call 2D_Map( v, q, NR ); V
2. initialization
max_tO=tpX=tpy=0;
min_tl= t^x=tqy=l;
accept=false;
3. trivial acceptance and rejection.
ifNR =3 .and.NR =3 then goto5 endif; {case2: trivially accepted }
U V
ifq *Uy
y then tqy=(q-Uy)/Ay y
endif;
i f tpX>tqy then goto 7 endif; { rejected }
Zy=Uy + tpX-Ay
else
max_tO=tpy
endif
endif;
5.2 exit point
ifNR =3then { v is interior to P then v is output }
v
w =Uy + tqX-Ay
y
else
min_tl=tqy
w =u + tqy-Ax
x x
w =q y y
endif
endif;
6. accept=true