Professional Documents
Culture Documents
Stephen I. Warshaw
ABSTRACT
NOTICE
Abstract.. ................... i
Distribution. . . . . . . . . . . .. .
.
. .
,. .' . . . . 40
.Preface arid Acknowledgements
. .
iii
Area of I n t e r s e c t i o n o f Arbitrary Polygons
I. Introduction
perform it 0 n . a s c a l a r type m c h i n e .
must be repeated
. . .
frequently, t h e area c a l c u l a t i o n can turn o u t t o be t h e
whether one floating' point number is larger than another. orm mall^, this
causes no problems. But if the numbers happen t o be..very close t o one
answer obtained because a wrong logical path was taken .) Therefore, our
it r e a l l y matters.
*
overlap-type calculations. To the author's knowledge, overlap area calculations
Lagrangian hydrodynamics calculations. The other type i s where one .of the
overlap a r e a ' calculation, and then consider the problem. ,associated with t h e
A. Convex Polygons
" bounded.
. .
left. This meafis t h a t a s one proceeds through the ordered list of vertices
! .
a s given, t h e boundary of t h e polygoc w i l l be traversed in a counter-clock-
w i s e sense. . ,
Figure 1.
.;f'
1
- A
F
i-1
1x
2
.
-2
ri) 2 0 . .. . .
(1,)
That is, none of these cross' products can be negative. ' If, when subjecting
One
. very.
. useful and powerful property of convex'polygons now deserves
t h a t t h e sides .of a convex polygon a r e edges of such half .planes. To. formu-
A
Note t h a t t h i s f o m l a t i o n i s oriented, because i f $ . and r2 are switched,
1.
( 2 ) w i l l define the other half plane. A s a consequence, the points
Figure 2
I I
pi, I?;+l,
define the vevltices of the other. (Here, we use the index labels i and j t o
distinguish the different polygons. Equation ( 3 ) is applied t o each ili
(of one polygon) f o r every adjacent vertex pair "r , + , (of the other
polygon). Any fail- of an ??i t o satisfy the relation
Now, if we find that all the vertices of one Lie inside the
other, then that polygon is inside, and we are done. The area o r volume of
f I
overlap is 'just that of the inner polygon.
Consider next the situation where same or all of the vertices of each
polygon l i e outside the other. Then a search must be! made f o r those pairs
of sides (one from each polygon) which cross each ather. (Recall from the
above that sides completely inside a r e exempt.)
The pcmer of the half plane concept is such that we can use it t o
analytically detect whether two sides intersect without having f i r s t t o
calculate the intersection point. Since a side se-t of a polygon l i e s
on the edge of one of VLat polygon's half planes, we.test t o see if one,
and only one vertex endpoint of one segment lies on the half plane of the
other, and conversely. I f this happens t o be so, an.intersection has been
found. 1f not (the endpoints of a segment l i e both ori or both o f f ) there
is no i n t e m c t i o n . I n Figure 3, .three possible arrangements are shown. The
shading symbolizes the. half planes. Only in the first' situation is them
Figure 3
I
a s follows: . , .,
x = l
A
[(f
j+l
x r.
1
3
- xi) - 2 A
(ritl x r .1) ( x. j + l - x J. ) ]
'
1 a. A
y -
A [(r.
.JII
x r.)(y
J ill - I/.)
1
- (ri+i.x rA3. )(y3+l
2
where
A = (fj + l - P.)
2
.
I x (ritl. --
A
.-
- .a
r1
.) '
area o r v o l of
~ revolution of the intersection polygon. I f one of the
a11 lines drawn ,fmm one vertex t o all the others. These lines r a d i a t e
. .
D. Non-convex Polygons
shown i n Figure 5.
Figure 5 .
Figure 7
between two polygons which may each have concave v e r t i c e s can be handled with
Consider
. .
two a r b i t r a r y polygons, P and Q. L e t 'them each be reformed
t t
as respectively convex envelopes P and Q , with corresponding concave
elements P-. and Q- . (That these sets of concave e l e m n t s may each contain
t
S = area of overlap between P and 'Q
0
t
S .'= area of overlap between P and Q-
1
S2 = area of overlap between Q
+ and P-
. ..
J
Figure 8 . .
The area of intersectj.nn, shown shaded, is calculated from Eq. (15 1, where :
GFH
S3 "a of overlap of "concave t r i a n g l e " GFH.with t h e "concave
E. Crossed ~ o l ~ ~ o n s
Figure 9
n o t be considered f u r t h e r .
111. Overlap Area Calculation Pathologies
method13' f o r t e s t i n g overlap a l g o r i t h m .
. . Figure 10
..
and f o r t h e BC-EF i n t e r s e c t i o n t h a t
-L
J'
sgnC(rF -J A A
rE)x XrB- rE)l#
J
sgnC(rF - -2
rE)x (rC-rE)1 (20
p r i n c i p l e , t h a t we can g e t i n t o trouble.
. .
-- lose. al.1. -three
However, i f these calculations a r e done by computer, we -can
-
t i o n s (161, (181,and (20). I f , and only i f we set up t h e coding i n t h e
algorithm s o ' t h i s assumption is guaranteed can w e absolutely j u s t i f y it.
a t i v e and d i s t r i b u t i v e l a w s f o r t h e a r i t h m e t i c of f l o a t i n g p o i n t numbers do
Not only' t h e values, but the signs of t h e cross product may vary.
,. ...
?
..
a p p ~ o a c lrn&
~ be prefer'iTedover .Ll le o h e r * . ,
t h e plane, as shown.
Figure 11
Let C be,shiftedperpendicular to AB toward the plane by a small amount
so it psts at C'. This shift can be obtained by calculating the coordinates
of C' from
-1
If t h i s t e s t f o r convexity a t Gi i s passed with t h e dunmy ritl, then we
s h a l l claim, i n t h e s p i r i t of t h e previous s e c t i o n , t h a t $.1 i s not a concave
point.
W
e note t h a t t h i s removal w i l l a l s o s i g n i f i c a n t l y l e s s e n t h e number of
follows .
From t h e maximum and minimum coordinate valuer;. oF the in-tr;rs:;r:c:-l .i or) 1'' I I y-
?: See Figure. 4
vertex points t h a t are suspected of redundancy. Then we ask i f t h e
following relationship i s s a t i s f i e d :
bined f i g u r e s -
cidence pathologies, and then c a l c u l a t i n g t h e i r area of overlap a s the corn-
signed t o ci r c ~ m v e n t .
XI = x cos a i y s i n a (29
and then, i f t h e need a r i s e s , directs t h e machine t o carry out the various sub-
polygons.
needs are. However, i f requested, t h e author w i l l provide the CHAT FORTRAN C51
A. Executive Routine
i t s concave t r i a n g l e s
1 0 . ' Apply : ( 1 5 ) .
(ii) I f t e s t f a i l s , go t o 1.
(iii)I f test passes, go t o ( a ) .
executive r o u t i n e .
C. Alternatives
We cannot, like Dr. Pangloss, claim the foregoing to represent the
best qf all possible worlds. -Thereare different ways of choosing and
arranging the operations in the algorithm; the contents of the previous
section represent one such way. Others may suggest themselves. For
example, we can offer three possibilities thought of, but not carried out.
One possibility arises from the observation that m y specific cross
products repeatedly calculated, as we showed, for example, in Part 111,
Section A. It m y well be worth the initial labor to rearrange the coding
so that not only are these cross products calculated just once, but the
resulting values (or signs) made easily accessible in some bookkeeping
scheme that optimizes efficiency of the overall calculation.
A second .schemeconsists of arranging the coding so there is no
need to carryout the ordering of vertices as outlined in Part 11, Section
C. Tho facts suggest this possibility. One is that the two sets of
o r i g i n a l polygon v e r t i c e s are formulated i n an ordered l i s t o f vertex
expensive.
s u r p r i s e s f o r t h e i r builders." [81
V. Appendices
them:
2 - 1
where rN + 1 = Since this holds f o r any "r (31) reduces t o
0'
which were a l s o swept o u t . From t h e theorem of' Pappus and (311, WP oi.,t.~
i.ri
A
which, since r and yC, are a r b i t r a r y , reduces t o
a
?\J
. .
B. ~ u r n e r i c a l~xambleof a Vertex-Line Pathology
e i l l u s r t r a t e t h e concepts i n P a r t I1 by a n ~ r i c a 1 , c a s e n c ~ u n t e r e d
W
t o l i e on t h e s i d e between
3 and $j+l.
r-.
J..
I
Figure 1 3
TABLE I
COORDTNRTES OF VERTICES
XIJI 1.72704683 17206722502561613577
L.1i.S. OF EQ. ( G I
CP-P-0
a~mmti~ o~m~rtic
Pase R ~ F Prb Paw Range Ww
001-025 S 3.50 326-3M 10.00
Q26-050 4.00 351-375 10.50
05 1-074 4.50 376-400 10.75
076- 100 5.00 401-425 11.00
101-I25 5.50 426-450 11.75
126-150 6.00 451-4'15 12.00
151-175 6.75 476-500 12.50
176-200 7.50 501-525 13.75
201-225 7.75 526-550 13.00
226-250 8.00 551-575 13.50
251-275 9.00 576-600 13.75
276-M0 9.25 601-up *
301-325 9.75
-
* ~ d d$2.50 for met, additional 100 p ~ g eincxement from 601 to 1.000 m;
add SZ.SO for each additinnal IN1 page iammenl over 1,000 ps@s.
TechnicalInformath Department
LAWRENCE UVERMORE I4BORAf;ORY
University of CaliforniaI t i n California 194550