An Efficient A L G O R I T H M For Line Clipping by Convex Polygon
An Efficient A L G O R I T H M For Line Clipping by Convex Polygon
417-421, 1993
Technical Section
2. PROPOSED ALGORITHM
It is obvious that the line p intersects the edge XoXl
of the given polygon if and only if the vector s lies
between two vectors So and si, see Fig. 1.
Let us define ~ and r/as the z-coordinate of the cross
products as follows
= [SXSi] z
71 :
[SXSi+l] :
i :
0 .....
N -
1.1. Algorithm 1
procedure Clip 2D Cyrus Beck ( XA, Xn );
begin { ! ! all vectors ni precomputed ! ! algorithm shortened }
i : - - 1; train: = - o c ;
tmax:= 00; S : = X B - - X A ;
{ for line segment train : : 0 . 0 ; tmax : = 1 . 0 }
while i < = N do
{ N is a number of edges }
begin
I ni is a normal vector, e.g. ni = [ sy,-Sx] T }
t and ni must point out of the convex window }
::
sTni;
Si : :
Xi -- XA;
418
V,~CLAV SKALA
(~>O)xor(~<O),
resp.
x4
~*~'<0
X2
Xl
Fig. 1. Line segment clipping by convex polygon.
(8,3,6,4,0)+(5,3,7,4,
I).N
2.1. Algorithm 2
ANALYSIS
(15,3, 11, 1 4 , 2 ) + ( 3 ,
I, 3, 3 , 0 ) * N
419
xo
XO
xo
xA
X1
sJ.
Xl
XI
c
Xo
~oV$1
s
xo
xI
x!
E
x~
xo ~
I s Xo
So
XA
SoV sl I
xl
$
H
XI
I
So
xa
X1
1
K
s1
XA "
V
L
420
V,~CLAV SKALA
Table 1. Possible cases.
~:
>0
>0
>0
=0
=0
=0
<0
<0
<0
>0
=0
<0
>0
=0
<0
>0
=0
<0
no--cases g, h
yes--special case 1
yes--cases a, c
yes--special case j
no--special case m
yes--special case k
yes--cases b, d
yes--special case i
no--cases e, f
lnt
Float
:--
<
14
204
42
260
10
80
40
82
58
154
4. EXPERIMENTAL RESULTS
T h e C-B a n d proposed algorithms have been tested
on data sets of end-points that have been r a n d o m l y
a n d uniformly generated over a space inside of a circle
in order to eliminate a n influence of rotation. Convex
polygons were generated as regular N-sided convex
polygons inscribed into a smaller circle. The results in
Table 4 have been obtained if80% o f the lines intersect
the window.
The coefficients u are in a good correlation with
theoretical results because the pessimistic estimations
have been taken for the theoretical analysis. It is necessary to point out that different tests might be used
instead o f shown cross product, e.g., test for detection
on which side of the given line p the point xi lies.
int
Float
:--
5
33
9
50
3
16
26
20
44
114
4
1.26
10
1.60
~ ~
2.09
Intersections do not
exist
4
1.75
10
1.87
~ w.~
1.97
5. CONCLUSION
The new efficient algorithm for clipping lines against
convex window has been developed. Edges of the given
polygon can be arbitrarily oriented. The theoretical
analysis showed the advances over well-known CyrusBeck's algorithm. Experimental results support the
theoretical analysis in spite of the fact that m a n y factors
have been omitted, like c o m p u t a t i o n a l cost with integers, etc.
All tests were i m p l e m e n t e d in C + + on a PC 3 8 6 /
387 25 M H z a n d PC 486 33 MHz. It can be expected
that for workstations the efficiency u will be higher than
for PC 486.
There is a hope that the proposed algorithm can be
modified for clipping lines against non-convex windows, similarly to [ 31 ].
4
1.30
10
1.74
~ c~
2.42
Intersections do not
exist
4
2.01
10
2.16
~ oo
2.29
REFERENCES
5
1.41
8
1.54
10
1.73
15
1.81
20
1.90
30
2.08
70
2.27
190
2.41
5
1.37
8
1.59
10
1.71
15
1.88
20
2.25
30
3.32
70
2.58
190
2.85
1. K. Akelcy and C. P. Korohkin, Efficient Graphics Processor for Clipping Polygons, US Patent No. 5 051 737
( 1991 ).
2. R. D. Andreev, Algorithm for clipping arbitrary polygons.
Comp. Graph. Forum 7, 183-192 (1988).
3. A. Arokiasamy, Homogeneous coordinates and the principle of duality in two dimensional clipping. Comp. &
Graph. 13, 99-100 (1989).
4. J. F. Blinn and M. E. Newell, Clipping using homogeneous
coordinates. Comp. Graph. (SIGGRAPIT78 ) 12, 245251 (1978).
5. J. F. Blinn, A trip down to graphics pipeline--Line clipping. 1EEE Comp. Graph. Appl. 11, 98-105 ( 1991 ).
421