You are on page 1of 47

DISCLAIMER

This report was prepared as an account of work sponsored by an


agency of the United States Government. Neither the United States
Government nor any agency Thereof, nor any of their employees,
makes any warranty, express or implied, or assumes any legal
liability or responsibility for the accuracy, completeness, or
usefulness of any information, apparatus, product, or process
disclosed, or represents that its use would not infringe privately
owned rights. Reference herein to any specific commercial product,
process, or service by trade name, trademark, manufacturer, or
otherwise does not necessarily constitute or imply its endorsement,
recommendation, or favoring by the United States Government or any
agency thereof. The views and opinions of authors expressed herein
do not necessarily state or reflect those of the United States
Government or any agency thereof.
DISCLAIMER

Portions of this document may be illegible in


electronic image products. Images are produced
from the best available original document.
AREA OF INTERSECTION OF ARBITRARY POLYGONS*
. .

Stephen I. Warshaw

ABSTRACT

The geometric aspects of c a l c u l a t i n g t h e area o r volume of t h e

region of overlap between two i n t e r s e c t i n g a r b i t r a r y polygons are

considered i n d e t a i l , f o r t h e purpose of adapting.them t o a workable

algorithm s u i t a b l e f b r a d i g i t a l computer. Such an algorithm i s

described, hnd c e r t a i n f l o a t i n g point a r i t h m e t i c . &mu>rst h a t occur

t h a t are detrimental t o t h e operation of t h e algorithm are a l s o d i s -

cussed. Methods f o r circumventing these d i f ficult'ies are presented.

NOTICE

rponvlrcd by the United S u l u Comnmcnt. Neither


the United Statu nor the United Sutcr Energy
R w c h and D c n l o p m n t Administration, nor any or
their rmployru, nor any o f theii mntractork
1UbCOnMClOn. or their crnployea. n n k u any
warranty, crprcu or implied. or a e u m s any legal
UPbUty Or rerponm%ililylor the accuracy,eornptrtcnem
or u+lulnem of any inlormation n ultur, p l H u n 9,
pro- d l d o u d , or represents ;hrPPiis urc would not

, ;'' This workW a s per8Tulrlled ujide~.. auspices of t h e United S t a t e c


Energy R c s c m h and Development Administration'under cgntract
No. W-7405-Eng-48. . .

i OF THIS DOCUMENT IS UNLIMITED


D~STR~FJUT~ON ,
Table of Contents

Abstract.. ................... i

11. Geometric Considerations


A. Convex Polygons . .
. . . . . . ,. ..... 5
B. Intersection of Tho Convex Polygons.' . ... 8
C. h e a of the Intersection Polygon . . . . . 12
.
D. Nonconvex Polygons . . . . . . :. . . . . 14
.
E .
Crossed Polygons . . . . . . . . . . . . . 17
111. overlap Area Calculation Pathologies '

A. - Vertex-Side, Vertex-Vertex and:Side-Side


.
Coincidences . . . . . . . . . . . . . . . 19
. .
B. Resolution of the Coincidence Problem. . . . 22
C: Almost Convex Polygons . .. .. . . . . . . 25
D. .
Redundant Polygon Vertices . , ;.. . , , . . . 26
. Kershaw's Rotation Test. .
E... ' . . . . . . . . . 27.
,

.IV. Overlap Area or Volume Algorithm


. A. Executive Routine . . . . . . . . . . . . . 29
. . . . 33
: '

B.. Overlap Area or Vol~vncCalcul.3tinn. .


C. Alternatives . .. .
. . .... . . . . 32
:.
V. Appendices
A. Area or Volume of Revolution OF a Plane
.
Polygon. . . . . . ..... . . . . . . . 34
B. . Numerical Example of a Vertex-Line
. .
Pathology. . . . . . . . . . . . . . . . 35

Distribution. . . . . . . . . . . .. .
.
. .
,. .' . . . . 40
.Preface arid Acknowledgements
. .

The material contained herein w a s assembled "on t h e back burner", a s

it w e r e , over t h e b e t t e r part of a few m n t h s . During and p r i o r t o t h a t

: tim, t h e authdr had many i n t e r e s t i n g discussions regarding problems o f

mpping with those who program f o r Lagrangian and Eulerian hydrodynamics

codes a t LU;taken collecti"ely these discussions ke-d t o indicate the

need f o r a doLwnent such a s this one, p a r t i c u l a r l y by those whose i n t e r e s t s

l i e i n carryingmapping concepts over t o vector o r p a r a l l e l type computers.

The author i s e s p e c i a l l y indebted t o David ~ershaw'f o r a stimulating

discussion i n which he provided him with a r a p i d and convenient m t h o d

of t e s t i n g h i s mterial on t h e computer, and f o r impressing upon him t h e

need f o r taking f l o a t i n g point arithmetic problems seriously. Were it not

f o r t h i s , t h e p r o j e c t t h i s paper represents miglt have taken longer than it

did. A l l references herein t o "D. Kershaw, p r i v a t e communication" a m t o

material touched on in t h a t discussion.

The a u t h w j.s a l s o indebted t o Jerry Owens f o r many discussions on

f e a s i b l e mthods o f a.d.apting t h e contents o f t h i ~p i p e r t o vcctor tqpc

machines. Thanks are due John Woodruff f o r catching.an apparent inconsistency

in t h e application o f t h e concave polygon methodology.. This r e s u l t e d not only

i n improvements t o t h e algorithm, but t h i s manuscript as w e l l .


. .

iii
Area of I n t e r s e c t i o n o f Arbitrary Polygons

Ste6hen I. Warshaw "

I. Introduction

The c a l c u l a t i o n of t h e a r e a of t h e region c;.mn to two plane, o v e r l a ~ r ~ i n g

polygons i s ' a simple matter. Much o f t h i s s i m p l i c i t y i s l o s t when the cal--

c u l a t i o n is done by a d i g i t a l coriquLerl, p a r t i c u l a r l y ' when speed and econouy

o f storage are serious considerations. I n this paper, we o u t l i n e t h e s a l i e n t

f e a t u r e s o f this calcullation, and present an approach t o an algorithm t o

perform it 0 n . a s c a l a r type m c h i n e .

There are t h r e e reasons f o r considering t h i s apparently t r i v i a l

c a l c u l a t i o n in . d e t a i l . F i r s t , those who use computer simulation codes based

on a p a r t i t i o n ' o f t h e plane i n t o a f i n i t e mesh o f polygonal cells o f t e n f i n d

it necessary t o . t r a n s f e r information from one such mesh t o another having

cells o f d i f f e r e n t shapes. A t some p o i n t i n t h i s mapping process, t h e areas

( o r volumes o f . revolution) of t h e region c o m n t o overlapping c e l l s must

be calculated. I f t h c number of c e l l s involved i s . l a r. g e , o r this process

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

most expensivg ' p a r t o f t h e process. It i s therefore d e s i r a b l e t o have i n

t h e c a l c u l a t i o n algorithm only those operations which s e e m e s s e n t i a l f o r

speed and e f f i c i e n c y . e present, a s e t o f such operations h e r e , with t h e


W

hope t h a t i f it is n o t an optimum choice, it may very well be c l o s e t o one.


. .
Second, an overlap a r e a c a l c u l a t i o n when done on a computer i n e v i t a b l y

contains plmgrarp-ing l o g i c t h a t d e ~ e n d son t h e r e s u l t of a comparison of two

f l o a t i n g p o i n t numberls. That i s , a t c e r t a i n places i n t h e coding, a decision


a s t o which of several paths t h e calculation is t o take w i l l rest solely on

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

another, t h e calculated difference m y be of e i t h e r sign. Such randomness is

not t h e f a u l t . o f the comparison i t s e l f , but i s due t o e m r s which each


..
nwnber has 'acquired in t h e calculations t h a t have led up t o them. These
e r r o r s are not' =onveniently predictable, and therefore & i t h e r are the

logical decisions t h a t rest on t h i s comparison. A5.a consequence, t h i s


.. . . .
randomness cAn and does create serious logical d w g e t o t h e r e s u l t , so

t h a t answers vastly d i f f e r e n t from the t r u e area are, obtained. (Few things

can be mre i n f u r i a t i n g than an absolutely precise, but' completely wrong

answer obtained because a wrong logical path was taken .) Therefore, our

second reason f o r considering these matters i s t o present mthods f o r


. .

circumventirig,, o r a t l e a s t minimizing t h i s logical'damage i n places where

it r e a l l y matters.

I n s a t i s f y i n g these two reasons, contradictions .may arise. If we

succeed in speeding up a calculation by a good choice of operations, we


' . m y well slow it down with coding designed t o eliminate the randomness dis-

cussed previbusly. On a vector type machine, it i s not yet c l e a r t h a t these

contradictions w i l l be mre e a s i l y resolved.

The t h i r d reason f o r , t h i s paper is t o provide a reference source f o r

*
overlap-type calculations. To the author's knowledge, overlap area calculations

on computers have existed f o r a long time, but l i t t l e , i f any, docmentation


. .

is conveniently. available, and what there i s does not e x p l i c i t l y address t h e


d e t a i l s of t h e a l o g r i t h m used. We suspect, however, t h a t what we present

here has much i n c o r n with some of t h e o l d e r algorithms, and s o it is hoped


, .
that those who'already have o r plan t o use overlap area algorithms, p a r t i c u l a r l y

f o r vector-type .machines, w i l l f i n d t h e contents o f . t h i s manuscript of value.


I

For t h i s . reason, a l s o , we have avoided any e x p l i c i t consideration of p e c u l a r i t i e s

c h a r a c t e r i s t i c of any given computer, except where.'it would serve f o r i l l u s -

trat ive purposes . . .

In campiiter simulation with f i n i t e mesh codes, two types of polygonal

overlap area 'calculations are generally distinguished. one type is where

both of t h e overlappirig polygons are a r b i t r a r y , as occurs i n rneshes of

Lagrangian hydrodynamics calculations. The other type i s where one .of the

polygons i s always a rectangle, as, f o r example, derived f m an Eulerian

hydrodynamics, m s h , where the m s h g r i d l i n e s are h t a i n e d p a r a l l e l t o t h e


. . . .
.. .
Cartesian coqrdinate akes. e treat only t h e f o m r type &-I t h i s paper,
W
. . .

since' t h e 1 a t t e r . t y p e has already been t r e a t e d by t h e author in a previously

published rnemrandum. [I1 Readers who compare t h i s with that memrandum

w i l l readily see 'why t h i s d i s t i n c t i o n has been m d e :' .a rectangular ( o r other

curvilinear orthogonal) grid offers a d i s t i n c t i v e l y ' d i f f e r e n t , and perhaps

e a s i e r approach t o the overlap area calculation than t h a t given here. While

it could be' suggested t h a t t h e a r b i t r a r y polygon approach' involve the e l m n t s


of a rectangular g r i d , this m y not be desirable. i f . t h e ~ c t a n g u l a ra l t e r -

native i s f a s t e r , as t h e author Thinks it is.

In what. follows, we shall: f i r s t give an outline of ' t h e geometry of the

overlap a r e a ' calculation, and then consider the problem. ,associated with t h e

f l m t j n g poi-nt' c ~ a r i s o nd e c i s i m prockss . Only those mathemtical


.: .

expressions t h a t are employed i n the algorithm used by t h e author w i l l be

considered in d e t a i l . Thus, t h e geometrical section f o l l a r i n g i s actually

a detailed description of t h a t algorithm.


11. ~ e o k t r i cConsiderations

A. Convex Polygons

We begin by discussing intersections of convex polygons, f o r by doing

so great simplifications i n t h e o v e r a l l calculation. are achieved.

A c0nve.x polygon i s one each of whose interirjr vertex angles i s not


. .
greater than 1800. This description i s consistent with the cano.nica1. defini-

t i o n of a convex region, whereby a region i s s a i d t o be convex i f a l l s t r a i g h t

line segments drawn connecting any two of i t s -point& l i e wholly within it o r on


i t s boundary. Thus, doughnuts and kidney beans a r e not convex s o l i d s , but

eggs and grapefruit are. Since t h e boundary of t h e region i s included i n

t h i s definition, convex regions a r e a l s o closed,simply connected, and

" bounded.
. .

One may prove t h a t the intersection of two convex regions i s again a

convex region. , ,(Details and proofs of t h i s and o t h e r matters r e l a t e d t o

what f o l l w s are given in reference C21. We s h a l l not present any proofs t o

support t h e m t h e m t i c a l s t a t e m n t s made here, but r a t h e r , r e f e r t h e reader


t o c23.1 . .

Before 'prdceeding f u r t h e r , we must e s t a b l i s h t h e conventions and


..
notation t o be used throughout. We specify any polygon by l i s t i n g i n s e r i a l

order t h e coordinates of its v e r t i c a . Thus, s t r a i g h t l i n e segments beginning

and ending on adjacent vertices in t h i s list wily define t h e periphery o t t h e

polygon. F u r t h e m r e , we specifiy the convention t h a t , i f we traverse t h i s

boundary from one vertex t o the next, the i n t e r i o r . o f the polygon l i e s t o


. .

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. . ,

By adhering t o these conventions it becomes convenient and useful t o


regard t h e s i d e s of any polygon as oriented s t r a i g h t l i n e segments, o r vectors.

Let a polygon be defined by N v,ertex points (x... y.. 1, i .= 1,2,. .N.


~ l t e r n a t i v e l y ,these v e r t i c e s can be represented by vectors $i
.1' .1
-
'Xi +3 *Y i
fr-& some o r i g i n t o t h e vertex points. Then t h e vector differences
2
r
it1
- ei w i l l represent these oriented s t r a i g h t l& segments, a s shown i n

Figure 1.

Now, i f ' a polygon is convex, t h e following r e l .a.t i o n s h i p holds f o r a l l

p a i r s of adjacent' s i d e s with c o m n vertex f 1. , a s s u i i n g ' t h e usual r i g h t -

h&ded coordinate system conventions : . .. .

.;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

an unknown polygon t o t h i s test, a vertex point Si c o m k t o two adjacent


.. .

sides is found f o r which'(.l) i s not t r u e , then t h i s vertex s h a l l be


. .

referred t o a s a concave vertex. Of t h i s , more lateF.

One
. very.
. useful and powerful property of convex'polygons now deserves

mntion: every.N-sided convex polygon is the intersection 0 f . N closed half


a.

planes. [ Since a closed half plane is t h a t pa&' of the plane l y i n g t o

one side of a s t r a i g h t l i n e and including t h e l i n e , it i s inmediately evident

t h a t t h e sides .of a convex polygon a r e edges of such half .planes. To. formu-

l a t e an analytic representation of a h a l f plane cons'istent with our conventions,

let gl and F2 define two points bn a s t r a i g h t l i n e . Then we s h a l l say t h a t


a A
- r.11.
'

a half plane i s a l l those points r lying on and t o the l e f t of (7?2

This means that the following inequality i s s a t i s f i e d by $:

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

t h a t define a ' convex polygon a r e given by the following


, ,
condition t h a t $
A
must s a t i s f y r e l a t i v e t o each of t h e vertex p a i r s ri and $i+l:

The order of Pi and si+l,is important, and must be as shdm. . A comparison of


(1)with ( 3) shows t h a t every vertex not lying on a s i d e of a convex polygon

i11us-k I,ie to 1;lle l e f t of it. . .


. . . .
When the equals sign in ( 2 ) holds, the equation of t h e l i n e i t s e l f
results. Then we o b t a h

B. Intersection of 'hm Convex Polygons


When two convex polygons overlap, t h e i r intersection is a l s o a convex

polygon. We n? a d d r y s the problem'of how t o t e l l a computer t o find the


vertices of t h i s intersection result.
An example of two intersecting convex polygons is shown in Figum 2,

when the region of intersection is shown shaded. Inspection of t h e figure


reveals that if any vertex of one polygon l i e s inside t h e other, that veMgx
-
is &So a vertex of the intersection polygon. These are labeled A, B, E, F
and H in t h e figure.
Q

Figure 2
I I

m e r examination also shows t h a t i f any two adjacent vertices of


one polygon l i e inside the other, then the side between them also lies
inside, and is therefore a side of the intersection polygon. In the figure,
these are sides AB and EF. Note that they do not moss any side of the other
polygon. These results are a direct consequence of the canonical definition
of a convex region given before.
To analytically t e s t if a vertex of one polygon l i e s inside the other,
we ask i f t h a t vertex l i e s on -
a11 the half planes of the other polygon. Let
a a
etc. be the vertices for one polygon, and let rj, rj+l, P ~ + ~ , . . .
4 & 9

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

f o r a l l j is sufficient t o reject it as an intersection ;polygon vertex.


That is, any vertex of one polygon lying outside the other is not part of
the intersection polygon. (See, e.g. vertices K, L, M, N , P and Q i n Figure 2).

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

Applying equation ( 3 ) , t h e following two r e l a t i o 9 s must be s a t i s f i e d


'

simultaneouslyin order f o r two s i d e segments t o i n t e r s e c t :

That t h e cross products involved have t o have d i f f e h n t signs is t h e same as

saying t h a t t h e .endpoints of one l i n e segment must each l i e on opposite s i d e s

of t h e o t h e r line s e g m n t , and conversely.


. .

On detection o f an i n t e r s e c t i o n , i t s coordinates.ase calculated

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
.) '

Note (10 a n d (11) can be combined t o produce t h e follawing "vector equivalent1':


. ..
(This is n o t a t r u e vector r e l a t i o n , since a l l t h e crcss products h ~ r rare

. symbols f o r . t h e i r algebraic equivalents in terms of x and y . ) One of t h e

virtues of t h i s p a r t i c u l a r approach is t h a t the q u a n t i t i e s used i n ( 8 ) and


. .
(9 ) may be saved i n the computer f o r the calculation i n (10 ) and (11).

C. Area of the Intersection Polygon

F r o m t h e vertices found by the previous t e s t s we m y calculate the

area o r v o l of
~ revolution of the intersection polygon. I f one of the

polygons l i e s - inside t h e other, t h i s area is e a s i l y .determined. I f not, then

a new problem a r i s e s : the vertices of the intersection.polygon have t o be

put i n proper order. I n keeping t h e previous calculations t o a rnhimum, we

have deliberately not kept t r a c k ' of the order.each found


. .
intersection polygon

vertex has r e l a t i v e t o t h e others, and now must determine it. ,

The f a c t t h a t t h e intersection polygon is known t o be convex permits

t h e proper ordering of ;.ts vet3ri.ces t o be found with l i t t l e d i f f i c u l t y . For

example, t h e centroid of a convex f i g m certainly l i e s within the figure,

and i f we draw radius voctors f r o m the centroid t o each' of the intersection

v e r t i c e s , these v e r t i c e s m y then be properly ordered according t o t h e i r

polar angles (compass directions of those vectors).


. ,

A perhaps. cheaper a l t e r n a t i v e i s t o consider d i r e c t l y t h e slopes. of

a11 lines drawn ,fmm one vertex t o all the others. These lines r a d i a t e

outward in a fanj and suggest the p o s s i b i l i t y of an ordering ba,ced ori the

cotangent o r tangents of t h e i r polar angles. The e s s e n t i a l s of t h i s rnethod


. , . .

are a s follows: choose a convenient vertex as the "base point", such a s ,

f o r example, t h e one f o r which its y coordinate is t h e &urn. Draw


- .
radius vectors from t h i s base point t o every other vertex of t h e i n t e r s e c t i o n

polygon, a s shown i n Figure 4.

I f we .consider t h e inverse slopes of a l l , these vectors, i.e . t h e


.Ax
-
- of each point r e l a t i v e t o t h e base point, then t h e points
cotan&nt r a t i o s
. AY

can be ordered according t o these r a t i o s . Ths, t h e proper ordering f o r

t h e intersection polygon points is a l i s t i n g of t h e. vertices


. in order of
. .

decreasing cotangent r a t i o , which, from Figure 4 , 2s indeed counter-clockwise.


That t h i s method'is valid rests solely on t h e f a c t t h a t the intersection

polygon is convex: these radius vectors always l i e within o r on the boundary

of the polygon', regardless of choice of base point. . "

. .

~ 'revolution of a polygon in terms of


Formulas, f o r the area o r v o l of
... .
its vertex coordinates are given i n Appendix A.
. ' I
I

D. Non-convex Polygons

. . The v i r t u e of t h e convex polygon approach lies i n the' f a c t t h a t it

. . m k e s t h e c a l c u. l. a t i o n of t h e area of i n t e r s e c t i o n of two a r b i t r a r y polygons


alrnost t r i v i a l . The reason f o r this i s t h a t any non-convex polygon m y be

recast i n t o a convex polygon and one o r mre completely flipped t r i a n g l e s .


. .
By various combhations of overlap of these convex elements, t h e c a l c u l a t i o n
. o f t h e genel$l case i s reduced t o a s h o r t sequence of computations involving
. .
only convex, figures .
A s an example o f t h i s r e s t r u c t u r i n g , consider t h e nonconvex polygon

shown i n Figure 5.

Figure 5 .

I f w e start a t v e r t e x A ahd apply t h e t e s t f o r . convexity given by

Eq. ( 1 ) t o each 'successive vertex, we f i n d t h a t t h e vertex a t E f a i l s t h i s


test, and F: i s therefore a concave p o i n t . A t t h i s juncture w e save t h e
. .
v e r t i c e s o f t .r.i a n g l e DF'E and a l t e r t h e polygon by rern3ving vertex E. Then
. . .
we repeat the' process ,over, s t a r t i n g one vertex back, i ..e. a t , C on t h e
reformed polygon shown i n Figure 6 . Now D i s found a l s o t o be a concave

poi.nt. I n exactly. t h e same manner, t r i a n g l e CFD i s saved, and the vertex at

D removed with the r e s u l t shown i n Figure 7 .

Figure 7

This second generation polygon is convex. It is with - t h i s polygon along


, ,

with t h e two "concave ' t r i a n g l e s " found t h a t t h e overlap calculations are

done, since noh,illl t h c :polygons involvcd r n convex.


Because of t h i s r e s t r u c t u r i n g t h e c a l c u l a t i o n - o f t h e area o f overlap

between two polygons which may each have concave v e r t i c e s can be handled with

Boolean.logic. . Nothing more is .involved than t h e construction of the appro-

p r i a t e Venn. diagram, using t h e "reduced" convex polyg&s and t h e i r adjacent

t r i a n g u l a r "concave e l m n t s " as .elements.

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

two o r more t r i a n g l e s o f f e r s no d i f f i c u l t y , because t h e t r i a n g l e s with*

each set do not overlap one another.) Let

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-

S j '= area of overlap between P- and Q-

Then t h e area of i n t e r s e c t i o n o f t h e two polygons P and Q i s

. ..

Equation (1.5) may e a s i l y be v e r i f i e d by regarding t h e above polygons as


.t t
p o i n t sets, where P P u P-, P n P- =
' 0, P A P- = P-, with analogous
. .
t t
r e l a t i o n s 'for. Q. I f P and Q are made t o overlap in a Venn diagram, it
t t
can r e a d i l y be observed t h a t So is t h e a c t u a l a r e a o f P Q i n the
t
diagram, S1 i s t h e area of P n Q- , and s o o n . By t h e appropriate

graphical superpositions, Eq. (15) is then obtained f o r S as t h e area of


A s an.example of t h e foregoing, consider the i n t e r s e c t i o n of two con-

cave five-sided polygons as shown in Figure 8.

J
Figure 8 . .

The area of intersectj.nn, shown shaded, is calculated from Eq. (15 1, where :

So =.. &,a of overlap. of q u a d r i l a t e r a l F H J K with t r i a n g l e ABE

S1 =:area of overlap o f q u a d r i l a t e r a l F H J K with t h e two "concave

triangles'' B E and BED

S2 = a r e a o f overlap of t r i a n g l e ABE with t h e ','conca"e triangle"

GFH
S3 "a of overlap of "concave t r i a n g l e " GFH.with t h e "concave

tri,ku-glesl' RDC and BED.


. .

The r e a d e r may s a t i s f y himself t h a t t h i s is s o ' b y drawing t h e actual

diagrams of t h e f o u r f i g u r e s represented by the Si:. :

E. Crossed ~ o l ~ ~ o n s

This discussion would be incomplete i f we did not consider a s i t u a t i o n

t h a t comes up frequently: t h a t where two o r more s i d e s of a given polygon

may indeed i n t e r s e c t . The simplest example of t h i s i s t h e "bowtied."


q u a d r i l a t e r a l shown i n ' Figure 9 , where two opposite s i d e s , AD and BC, i n t e r -
. . . .
..
sect a t E.

Figure 9

There i s n o t h i n g about crossed polygons t h a t t h e kthodology developed up

t o t h i s point cahnot 'handle; t h e decomposition process. w i l l a l s o work f o r

them. ~ i ' f f i c u l t yarises only i f no provision i s made t o accept overlap

area results t h a t are negative, o r no allowance is m d e . f o r negative corn


. ,

ponents of a r e a s of crossed polygons, such as represented by e i t h e r t r i a n g l e

ABE o r EDC o f Figure 9.


'

This p r o b l e m t i c a l s i t u a t i o n arises when computations are required of

a r e a s of overlap between crossed polygons t h a t d e v e 1 o p . h twisted meshes i n ,

e.g.,Lagrangian .hydrodynamics s t u d i e s . Regardless of which algorithm they


. . choocc t o pursue t h e matter, t h n s p who c a l c u l a t e these areas must be a b l e t o

provide usable ,and cons; stent in t e r p r e t a t i o n s of negative F a components.

These i n t e r p r e t a t i o n s are r e a l l y outside t h e scope of t h i s paper, and w i l l

n o t be considered f u r t h e r .
111. Overlap Area Calculation Pathologies

Problems w i l l , arise i n t h e overlap area c a l c u l a t i o n i f t h e l i m i t a t i o n s

inherent in h computer f o r handling real numbers a r e ignored. In t h i s part

we s h a l l discuss these problems i n d e t a i l , and then describe Kershaw's

method13' f o r t e s t i n g overlap a l g o r i t h m .

A. Vertex-Sidc, Vertex-Vertex and Side-Side Coincidences

Consider a case where two overlapping polygons are s i t u a t e d s o t h a t


.. .
a vertex of .one l i e s on a s i d e of t h e o t h e r , a s shown i n F i g u r e 1 0 .
F

. . Figure 10
..

I n t h e . p r o c e s s of finding i f point B i s p a r t of the i n t e r s e c t i o n polygon,

a test i s made t o s e e on which s i d e o f l i n e EF point .B lies. This i s done

by asking i f the, following condition holds:

which is j u s t E ~ (. 3 applied t o t h e process. If (16 i s not s a t i s f i e d ,


the11 B is assbiked -I-" l i e ouLsi.de Lriargle GEF, a_ng w would expect two in-

t e r s e c t i o n s t o be found' near B: one occurring between l i n e s e g m n t s BC and


. .
EF, and the o t h e r between AB and EF. Applying Eqs. ( 8 ) and ( 9 ) f o r d e t e c t i o n

: of an i n t e r s e c t i o n , we would expect f o r t h e AB-EF i n t e r s e c t i o n t h a t

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

Notice t h a t 'the cross product in (16) i s repeated in t h e r i g h t s i d e df

(18) and t h e . i e f t s i d e of (20). If (16) is not s a t i s f i e d , t h i s cross product

is negative, and we would therefore expect t h a t both t h e l e f t s i d e of (18 1

And t h e r i g h t s i d e of (20 would have p o s i t i v e sign. Indeed, f r o m inspection

of Figure 10,' we f i n d t h i s is so. The signs of t h e o t h e r cross products a l s o

appem equally' unambiguous.

Theoretically, at least, t h e r e i s no d i f f i c u l t y . ' E i t h e r B l i e s on t h e

l i n e EF, t o t h e l e f t of EF, o r t o t h e r i g h t of EF.


. .
or' these first two cases
(16) w i l l b e . s a t i s f i e d , and f o r t h e t h i r d case w h e r e - i t i s n o t , t h e two in-

t e r s e c t i o n s w i l l be detected and c a l c u l a t e d . There. .i s t h e r e f o r e no way, i n

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

points! The assumption underlying a l l the above i s t h a t t h e cross pmduct


A A
( P ~- A
rE)x (rg rE) w a s calculated s o as t o have i d e n t i c a l values i n equa-

-
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.

Otherwise, anything can happen.:: In a f i n i t e , w o r d s i z e machine, t h e associ-

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 hold. I f , f o r reasons of speed and e f f i c i e n c y w e should choose vari-

ously d i f f e r i n g c a l c u l a t i o n a l paths t o reach t h i s cross product a t each of

t h e t h r e e places indicated by (161, (18) ,and ( 2 0 1 , then we have given up

t h e assurance t h a t t h e r e s u l t s of (161, (18) and (20). w i l l be c o n s i s t e n t .


. .

Not only' t h e values, but the signs of t h e cross product may vary.

I n Appendix B, we give an actual.example of a . c a s e where, a f t e r having

decided t h a t ' B w a s outside GEF, t h e algorithm then passed on t o decide t h a t


. .
n e i t h e r AB nor BC i n t e r s e c t e d EF. The r e s u l t w a s t h a t . B w a s e f f e c t i v e l y

eliminated, and t h e algorithm calculated t h e overlap area between t r i a n g l e

GEF and the " l o g i c a l l y mutilated" t r i a n g l e ACD. The answer w a s p r e c i s e ,


. .
t o be sure, but very, very wrong.

This pathology is c h a r a c t e r i s t i c of a l l s i t u a t i b n s where a vertex of

one polygon lies. anywhere on t h e boundary of t h e o t h e r . . By "on" w e mean a t

t h e machine l i m i t , where t h e last few b i t s may determine the f u t u r e course


. .
of c a l c u l a t i o n s involving t h a t vertex. .Vertex-vertex o r side-side coin-

cidences are in p r i n c i p l e no d i f f e r e n t from vertex-side.coincidences,since

i n a l l cases t h e sam test a p p l i e s : t h a t f o r the l o c a t i o n o f a point in respect

of a line. Except f o r c e r t a i n p e c u l i a r i t i e s t o be discussed further on,


. .
t h e r e appears .no need t o consider here point-point cornparisoris as such.
.. .

,. ...
?
..

and it w i l l . . (Murphy's Law)


B. Resolution of t h e Coincidence Problem

There a r e two ways t o g e t around t h e d i f f i c u l t y posed by coincidences.

One way i s t o arrange t h e coding s o t h a t once a p a r t i c u l a r cross product i s

c a l c u l a t e d , t h e r e s u l t i s saved t o be used again i n o t h e r p a r t s of t h e code

t h a t need it. : A considerable m u n f of bookkeeping.and storage may r e s u l t ,

not t o mention t h e p o s s i b i l i t y of l o s s e s i n speed a d e f f i c i e n c y . The o t h e r .

way is t o judiciously apply tolerance checking, a s w i l l be described below.

Depending on t h e applications intended f o r t h e overlap area algorithm, e i t h e r

a p p ~ o a c lrn&
~ be prefer'iTedover .Ll le o h e r * . ,

I n t h e tolerance approach, decisions a r e made based on how c l o s e t h e

coincidence i s . A s it turns o u t , t h i s i s s u r p r i s i n g l y easy and cheap t o do,

s i n c e t h e cross product formalism lends i t s e l f q u i t e n a t u r a l l y t o it.

I n employing cross products t o c l a s s i f y a vertex, t h e pwpose has been

t o determine on which s i d e of an oriented l i n e a point lies. The viewpoint

taken w a s a l w a y s whether the point f e l l on o r o f f t h e. .associated h a l f plane,


. .

and a l l t h e d'ifficulties mentioned in t h e pr+vious s e c t i o n have t o do with

points "teetering on t h e edge". I n Figure 11, consider an oriented l i n e

segment AB, where i t s associated h a l f plane lies t o i t s l e f t as the l i n e i s

t r a v e r s e d . f r o m ' A . t o B. Suppose a p o i n t , C , t o l i e very c l o s e t o AB, but o f f

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

where t is a.small,positive proportionality factor measuring the amount


and direction of the shift. (If t was negative, the shift would be in the
opposite direction.)
Then, if application of Eq. .(3) in determining where C'. is.relative
to AB shows C' to lie on the half plane, we shall claim that the unshifted
point C lies on the half plane within a factor of tolerance t.
There are two attractive features of this proposal. First, t is a pro-
portion, equal to the ratio of the shift distance CC."to the length of AB.
Thus, this tolerance test scales according to the size of the line segment,
. .
i.e. is not .&solute. Second, its implementation is extremely simple. For
resolution of the coincidence problem, the only place we need to apply it
is where a decision is m d e on whether a vertex of,apolygon lies inside the
other, viz. ~ q .( 7 . -5
In this equation, r1. is the in question. On
applying the dunmy shifts represented by (22) and (23) to its coordinates
x1. and yi , the following "tolerimce-augmented" 101711 q i ( 7 ) i-s 01, I:, i-r I C V I :

where Axj -- X j + l - xj y and Ayj = yjtl - yj. The vector. equivalent of ( 2 4 )


'

may easily be shown to be


which i s j u s t t h e tolerance-augmented form of ( 6 ) . Since t h i s dumny s h i f t
1
of $.
1
is toward t h e i n s i d e of t h e polygon two of whose v e r t i c e s are r
j
and
A
r. j+13 we s h a l l claim t h a t any f a i l u r e of t o satisfy ' ( 24 ) o r (25 ) f o r a l l

j is s u f f i c i e n t t o r e j e c t Fi a s a vertex of t h e i n t e r s e c t i o n polygon, within


'

tolerance t . ,An example of t h i s application i s given a l s o i n Appendix B.

The reason why this i s t h e c r u c i a l place t o apply the tolerance test

and not a l s o during t h e search f o r side-side i n t e r s e c t i o n s as represented by

( 81 and (9 ) i s t h i s : once a vertex very s l i g h t i y o f f a s i d e has been i d e n t i f i e d

within tolerance as an i n t e r s e c t i o n polygon vertex, t h e subsequent c a l c u l a t i o n

of t h e s i d e - s i d e . i n t e r s e c t i o n s which occur a t t h i s vertex w i l l not r e a l l y

matter. Both t h e two i n t e r s e c t i o n s ( i f found) and t h e vertex w i l l be s o


2
c l o s e t o g e t h e r . t h a t t h e a r e a o f the t r i a n g l e they form w i l l be of o r d e r t

of t h e main overlap r e s u l t . I f t i s s u f f i c i e n t l y small (say ~ 1 0 - lo ~r 1 0 - l 4

f o r a 60-bit machine), t h e e r r o r made i n omitting t h i s small t r i a n g l e m y not

F i n a l l y , w e observe t h a t an argument could indeed be made f o r a l s o applying

t h e tolerance ,approach t o ( 8 ) and ( 9 ) , but i n t h e opposite sense, v i z ., t o


r e j e c t found side-side i n t e r s e c t i o n s t h a t a r e very c l o s e o r "on t o p of" a

found vertex. Since t h e number of side-side combinations i s much l a r g e r than

t h e sum of t h e v e r t i c e s of 'bcth polygons, t h i s approach should be rmde gingerly


. .
if canputational speed i s of t h e essence. However, such m l t i p l ~degenerate
v e r t i c e s of an i n t e r s e c t i o n polygon do not s u b s t a n t i a l l y a f f e c t ' t h e accuracy

of t h e m i n r e s u l t , except f o r a s p e c i a l s i t u a t i o n t o be mentioned f u r t h e r on.


C. Almost Convex Polygons

Another place where t h e above tolerance check proves u s e f u l i s when a

polygon is i n i t i a l l y t e s t e d f o r concave p o i n t s . , , ' T h i s a p p l i c a t i o n i s likewise

easy,, a n d . w i l 1 be sketched b r i e f l y here.

If a polygon i s very s l i g h t l y concave a t one' of. i t s v e r t i c e s , then t h e

area of t h e s a v e d "concave t r i a n g l e " (see P a r t 11, Section D) may be s o


. .

small as t o not be worth involvtng in t h e subsequent overlap c a l c u l a t i o n s .

What can be done f o r t h i s s i t u a t i o n i s t o apply tolerance checking t o Eq.


A
( l ) ,which t e s t s f o r convexity. i n ( 1 ) with its
Thus, i f we replace r
i+l
dunmy-shifted counterpart as prescribed in ( 2 2 1 a n d ( 23 , w e are e f f e c t i v e l y
A
straightening out o r making convex t h e p o t e n t i a l l y concave vertex a t ri.

(Consider, f o r example, v e r t i c e s C , D and F i n Fi- 6, corresponding t o i-1,

i and i+l. On carrying out t h e indicated replacement


'
[xitl - t (yi - yi-l 1
f o r xitl andyitl + :(xi - xi - 1) f o r Yi+l] we o b t a i n , in place of (11,

-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.

I n t h i s connection, suppose a vertex ,gi s a t i i f i e ? ( 2 6 ) f o r t p o s i t i v e ,


L
but fails it. when t i s made negative. Then f o r a i l p r a c t i c a l purposes ri
. A
m y be s a i d t o l i e on t h e s t r a i g h t line joining Gitl and ri - and thus may

be omitted s a f e l y from t h e o r i g i n a l polygon vertex &ay. I f w e decide t o

s o p r e s e l e c t i t s v e r t i c e s a t t h e same time a polygon i s undergoing tests

f o r convexity, then we p o t e n t i a l l y 'gain in o v e r a l l speed of computation.


D. Redundant Polygon Vertices

Suppose e i t h e r of t h e overlapping.polygons has two adjacent v e r t i c e s

t h a t l i e p r a c t i c a l l y on t o p of one another. I f we allow these points t o be

c a r r i e d through t h e overlap process as described s o f a r , then we run t h e r i s k

of a series of "almost zero" cross product ~ r o b l e m ss j m i l a r t o those

previously encountered. It t h e r e f o r e becomes d e s i r a b l e t o remove t h i s redun-

dancy. A s it t u r n s o u t , t h i s i s automatically taken c a r e of by t h e t e s t s

given on the.previous page f o r screening c o l l i n e a r v e r t i c e s . I f w e consider


A A A
r . and of t h e previous page t o be coincident, then by t h i s test ri w i l l
1

be r e b v e d . The coincident case i s a p a r t i c u l a r case of t h e c o l l i n e a r one,

as t h e only difference 'here i s i n t h e r e l a t i v e proximity of t h e two points.

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

operations required f o r t h e overlap c a l c u l a t i o n .

Next, consider t h e s i t u a t i o n where some of t h e found points of t h e

i n t e r s e c t i o n polygon t u r n out t o be likewise coincident. No d i f f i c u l t i e s

w i l l arise uniess, during t h e ordering of t h e v e r t i c e s , t h e "base point" used

f o r t h e ordering:': is a multiple point. Then t h e pol.& cotangents calculated

f m m these points would be ratios of "almost zem" numbers, and, a s with

t h e amst zero cross products, can t a k e on any value whatever. Since we s t i l l

have y e t t o order the v e r t i c e s , t h i s base point redundancy'has t o be removed

by a d i f f e r e n t scheme than any considered s o f a r . ' One way t o do s o is a s

follows .
From t h e maximum and minimum coordinate valuer;. oF the in-tr;rs:;r:c:-l .i or) 1'' I I y-

gon v e r t i c e s we c a l c u l a t e t h e d i f f e r e n c e s AxD = x,,- ' x,liIl = Y-


and. a y ~ -

Ymin ' These a r e t h e x and y diameters of t h e polygon.


.
2
Let a represent t h e
chosen base p o i n t , and denote r one of t h e possibly coincident polygon
m

?: 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 :

where t is a r e l a t i v e tolerance f a c t o r . If (27) i s s a t i s f i e d , then f and


3
r m y be regarded a s coincident,and,one o r t h e o t h e r ignored. This test
0

is an order of magnitude comparison between t h e separation of t h e two points


and t h e diameter o f t h e polygon, and as with t h e previous tolerance checking

of cross products, likewise s c a l e s with t h e s i z e of t h e polygon.

E. Kershaw's Rotation Test

A severe. machine test of an overlap algorithm a s suggested by Kershaw [31

'consists o f d e l i b e r a t e l y s e t t i n g up two polygons which contain vertex coin-

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-

r i g i d l y r o t a t e d through various angles about some n r i g i n .

soon& o r l a t e r , because of t h e truncation and round o f f e r m r s inherent i n

c a l c u l a t i o n o f. .. t h e s i n e s and cosines of t h e r o t a t i o n angle, a s i t u a t i o n w i l l

be produced t h a t w i l l test a l l t h e "bad" cases t h e tolerance checks were de-

signed t o ci r c ~ m v e n t .

For example, consider t h e i n t e r s e c t i o n of two t r i a n g l e s shown in Figure


. .
12. Wherever t h e o t h e r vertex points happen t o l i e , a vertex-line coincidence

i s forced by p u t t i n g i n t o the computer program a c a l c u l a t i o n of a vertex

point of one polygon (A) t o l i e on a s i d e (DE) of the other;


Thus, we ask the computer t o c a l c u l a t e t h e coordinates of A from

where f is some proportion between 0 and 1. Then we mtate t h i s e n t i r e


.. .
c o l l e c t i o n of points through S O E angle k a by applying t h e transfo-tion

XI = x cos a i y s i n a (29

y' = y MS a x sin a (30)

t o each o f .the -points. This i s likewise done by t h e computer. What w i l l

tl1ri.1 happell i s l&t as successive angles are used,, t h e , locations of the

points r e l a t i v e t o each o t h e r as seen by t h e machine ' w i l l experience j i t t e r

because of t h e fmncation and roundoff produced i n ( 29 )' and ( 30 1. For some

angles a , t h e r e f o r e , A w i l l l i e on one s i d e of DE, f o r o t h e r s it w i l l l i e on the

o t h e r s i d e , and f o r s t i l l others it w i l i "vanish" in the overlap c a l c u l a t i o n s .


This t e s t w a s used t o generate t h e material presented i n Appendix B.
IV. Overlap Area o r V o l m Algorithm

The overlap area algorithm developed by t h e author based on the preceding

outlines divides naturally i n t o two parts. The f i r s t p a r t i s basically an

executive routine, which examines and reprocesses t h e polygons f o r convexity,

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-

sequent overlaps between convex and concave parts. The second p a r t i s t h e

overlap calculation i t s e l f , which is designed t o s p e c i f i c a l l y handle convex

polygons.

Only t h e broad aspects of the algorithm w i l l be sketched here, since it

w a s f e l t no useful purpose would be served by a c t u a l programming d e t a i l ; those

who intend t o use it are b e t t e r judges in t h i s respect 'of what t h e i r own

needs are. However, i f requested, t h e author w i l l provide the CHAT FORTRAN C51

source deck containing t h e algorithm which he used.

In what follows, a l l numbers i n parentheses are e.quation nwnbers of t h i s

paper, and every indentationrepresents a FORTRAN DO loop.

A. Executive Routine

1. Get and s t o r e coordinates of vertices of each polygon

2. Check each' polygon f o r concave vertices: loop over contents of vertex


8

lists f o r each polygon.


. .

a ) Apply t e s t ( 2 6 ) with negative t t o vertex. I f t e s t passes, skip t o f ) .

b) Apply t e s t ( 2 6 ) with positive t . If t e s t passes, skip t o . d l .

C) A'concave vertex is found. Save "concave triangle"


and keep count.

d) Delete vertex from o r i g i n a l l i s t .

c Eclclc up- one vertex go Lack Lo d) .


f) Calculate x and y d i f f e r e n c e s of adjacent v e r t i c e s a n d save.

Calculate area o r volume of overlap S0 between first and second

polygons as outlined i n B, following.

I f no.concave elements i n e i t h e r polygon, r e t u r n t o c a l l i n g r o u t i n e .

Save v e r t i c e s of second polygon in s c r a t c h storage.

If applicable, loop over concave t r i a n g l e s found f o r second polygon.

a) F i l l second polygon storage s l o t s with v e r t i c e s of t r i a n g l e .

b) Calculate area o r volume of overlap as in B;

C) ACC-late these overlap values i n S1.

Return v e r t i c e s of second polygon t o t h e i r o r i g i n a l s l o t s .

I f applicable, loop over concave t r i a n g l e s found f o r first polygon.

a) F i l l f i r s t polygon storage s l o t s with v e r t i c e s of t r i a n g l e .

b) Calculate area o r volume of overlap as i n B.

c) Accumulate these overlap values in S 2 .

Lmp over concave t r i a n g l e s of first polygon.

a) ill' storage s l o t s of f i r s t polygon with saved v e r t i c e s of i t s


concave t r i a n g l e s .

b) Loop over curlcave L~~idlgles


of second polygon
. .

. F i l l storage s l o t s of second polygon with saved v e r t i c e s of

i t s concave t r i a n g l e s

( i i ) Calculate area o r volume of overlap as in B.

( i i i ) Accumulate these overlap values in S.


3'
. .

1 0 . ' Apply : ( 1 5 ) .

11. Return t o c a l l i n g routine.


-
B. Overlap Area o r Volume Calculation
1. -Loop over v e r t i c e s of first polygon.

a) Loop over v e r t i c e s of second polygon (i.e ., the sides1

(i) Apply test ( 2 4 ) .

(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 ) .

b) Save coordinates of v e r t e x of first polygon.

c 1 'Increment i n t e r s e c t i o n polygon vertex c&t by 1.

2. Check ve'eex count. If equal t o number of v e r t i c e s of first polygon,

c a l c u l a t e i t s a r e a from ( 33) o r v o l u m & f ~ (36 and r e t u r n t o

executive r o u t i n e .

3. Repeat 1. and 2. with roles of polygons reversed.

4. Loop over v e r t i c e s of f i r s t polygon (i;e.,.the sides).

a)' Loop over1 ver.tices of ssecolld polygon (i.e.. , the s i d e s ) .


( i ) Apply
, LesLs ( 8 ) + ~ c l ( 9 )

(ii). I f e i t h e r test f a i l s , go back t o ( a ) .

( i i i ) If both t e s t s pass, i n c m n t vertex count, apply ( l o ) , (1.1)

and ( 1 2 1 , and save these i n t e r s e c t i o n coordinates.

5. Check vertex count t o be 3 o r greater. If n o t , set area o r v o l m

t o zero, and r e t u r n t o executive r o u t i n e .

'6. The saved coordinates are v e r t i c e s of t h e i n t e r s e c t i o n polygon; Find


maximum and minimum x and y values, and set highest vertex to be the
base point (Part 11, Section C).
7. Remove redundancies from base point (Part 111, Section D).
8. Loop over saved coordinates. Calculate and save polar cotangents
relative to the base point. (Part 11, Section C).
9. Order ve'iticesof intersection polygon by polar cotangent value.
10. Calculate for intersection polygon area from (331 or volume from ( 361.
11. Retup to executive routine.

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

coordinates. The o t h e r is t h a t in c a l c u l a t i n g side-side i n t e r s e c t i o n s ,

only one main loop w a s needed over t h e v e r t i c e s of one polygon. We d i d

not need a similar main loop over t h e o t h e r . (See ,step 4. of B . , above)

Onecould therefore keep t r a c k of t h e ordering of t h e i n t e r s e c t i o n polygon

v e r t i c e s as they are fo'und. The bookkeeping required t o do s o would be by

no means t r i v i a l , but perhaps worth t h e e f f o r t in t e r n of avoiding a rela-

t i v e l y expensive ordering procedure.

I n t h e t h i r d p o s s i b i l i t y , consider two convex polygons t h a t a r e

being considered f o r overlap. a l l of t h e v e r t i c e s - of onepolygon l i e


If -

o f f even one h a l f plane of t h e o t h e r , then neither<polygonw i l l i n t e r s e c t

t h e other. This procedural check might be useful i n , a preliminary screen-

i n g t o see i f an i n t e r s e c t i o n i s a t a l l possible. However, it may be

expensive.

".....Instead of t h e i n s i d e of a system being p e r f e c t l y hidden, it is

p e r f e c t l y revealed -- a white box r a t h e r than a black box ..........however,


because of our l i m i t a t i o n s , no box i s ever. e n t i r e l y revealed t o u s , even i f

w e construct it ourselves. Even t h e simplest systems sometimes contain

s u r p r i s e s f o r t h e i r builders." [81
V. Appendices

A. Area o r Volurne .of Rsvolution o f a Plane Polygon


,.

In Figure 1, suppose any point be marked on the plane f r o m which


. . C
-. r a d i u s vectors, A
r - .J
r a r e drawn t o t h e v e r t i c e s of t h e N-sided polygon.
i 0
.'Then t h e area o f t h e polygon i s t h e sum of- the areas of a l l t r i a n g l e s whose

s i d e s are two adjacent radius vectors and t h e common polygon s i d e between

them:

2 - 1
where rN + 1 = Since this holds f o r any "r (31) reduces t o
0'

Suppose now t h i s polygon i s r o t a t e d about t h e x-axis, sweeping out a

tomid whose clioss-section i s the polygon. 'The volume of t h i s t o r o i d is

likewise t h e sum of t h e volumes of a l l t h e t o r o i d s of t r i a n g u l a r s e c t i o n

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

when Kershawts t e s t 5 w a s applied t o a configuration s i m i l a r t o those shown i n

Figures 10 and 1 2 . This c a l c u l a t i o n was done on t h e CDC 7600 computer. ( 6 ) 1n

t h a t machine(7.?, f l o a t i n g point numbers are represented by a s t r i n g of 60

binary b i t s ( 2 0 o c t a l places) where t h e lef-tmost 1 2 . b i t s ( 4 places) contain

s i g n and exponent values, and t h e rightmost 48 b i t s (16 places) contain t h e

value of t h e number. The l e a s t s i g n i f i c a n t b i t s are t h e ones a t t h e r i g h t .

Figure 1'3 shows s c h e m t i c a l l y t h e i-elevant vertex-line geometry. The

labels i and j d i f f e r e n t i a t e two polygons. Vertex T?. w a s calculated s o a s


1.

t o l i e on t h e s i d e between
3 and $j+l.

r-.
J..
I
Figure 1 3

This conf i'guration was successively r o t a t e d through small angular incre-

ments, and each time t h e overlap area calculated. A t s e v e r a l such times,


-
P a r t I i i . Section E .
.1:-.-
-L1
vertex-line logical damage occurred where the vertex at r seenungly "vanished"
j
from consideration. For one such situation, the numerical values for the
coordinates of the vertices in the computer were as s h m in Table I, where
both conventional and octal representations are given, corresponding to the
easily decipherable FORTRAN symbols. . .

TABLE I

COORDTNRTES OF VERTICES
XIJI 1.72704683 17206722502561613577

In Table 11, on the n ~ x pi~ge.,


t the resulting factors and cross products
are shown corresponding to those in Eqs. ( 6 ) and ( 7 ) for vertex *i relative
. .
.-'
to side Y;+~ - r as well as those for corresponding terms in Eqs . ( 8) and ( 9 )
j '
-2. . .-
which test the intersection of the two sides ritl - r. and
1
Gjtl- 6j In this
table we also show the FORTRAN combination actually used to achieve the
numbers given. In the interests of clarity, the results for the intersecti.on
1 . .\ (L . ..-L
of sides ri - ri-1 with rjtl - r.3 are not given, as they were identical to
the intersection resul-tsllc:m,.
TABLE I 1

EQUATION FIND FORTRAN SEQUENCE ' CALCULATED WLUE


L.H.S. OF EO. ( 7 )
DX(J)=X(J+l)-X(J)
P=DX(J)*(Y( I ) - Y ( J ) )
R.H.S. OF ED. (7)
DYCJ)=Y(J+l)-Y(J)

L.1i.S. OF EQ. ( G I
CP-P-0

L.H.S. OF Ea. (81 .


DA(J)-X(J):I(Y(J+I)-X(J+~)*Y(J) 0. 00000000000000000068
Cf'=DX(J) 6cLft11-D'f(J) Q}<( 11 +DA (.TI
R.H.S. OF EQ. '(.8)
CP*DXIJ);~YSI+~)-YY(J)I~XCI+~)+DA(J) 1.79822972 17207142614413056604
L.H.S. OF EO. ( 9 )
DR(I)=X(I)N~Y(I+!)-X(I+l)XY(I)
CP=DXII)N<Y(Jl.-DY(I)xX(J)+DA(I) (NOT CALCULATED BECAUSE
TEST AT ( 8 ). FAILED.)
.
R . H . S . OF ED. ( 9 )
C P ~ D X ( ~ i ' r : ' ( 'J( - t l )-DY(f)X'X(J+!.)+DR( 1)

From Table I1 w e see t h a t not o n l y . d i d t h e tests a t " ( 6 ) and ( 7 ) f a i l ,


but s o did t h e test a t (81, since both s i d e s o f ( 8 ) w e r e regarded as p o s i t i v e .

(One might argue t h a t an i d e n t i c a l l y zero value be regarded as "neutral"

and coding put in.accordingly. The trouble with t h i s i s . t h a t t h e CDC 7600

has two 60-bit representations f o r a f l o a t i n g point zero m, each. of which

m y be i n t e r p r e t e d as "to." and "-O.", and s o nothing is' gained thereby.)

Note a l s o t h a t t h e ' l e f t is& of ( 7 ) di.ffers from t h e . r i g h t s i d e in t h e last

t h r e e binary b i t locations ( 2 i s 010 and 5 is 101).


TRBLE 111

EOURTION R.ND FORTRQN SEQUENCE CRLCULRTED W L U E


L.H.S. OF EQ. (24)

R.H.S. OF €0. (24)


DY(J)oY(J+l)-Y(J) -1.88944113 60878342331382763620
QmDY(J)*(X( I)-X(J)-TClL*DY(J) 1
L.H.S. OF EQ. (25)
CP -P-0

F i n a l l y , ' , i n Table 111, w e show t h e e f f e c t s of applying tolerance checking

t o t h i s , s i t u a t i o n.- Instead of t e s t s a t ( 6 and ( 7 , the corresponding tests

a t ( !A5 and ( 24.) w e r e applied, with a tolerance f a c t o r of t ' 10-14. Now, t h e


vertex a t r
. A
. was
1
"ca1.cul.ated" t o l i e on the i n s i d e of t h e polygon, and r . w a s
2
.

made a vertex'of t h e i n t e r s e c t i o n polygon.. The e f f e c t s of t h i s dummy s h i f t are

c l e a r l y e v i d e n t , m t h e last two.places of t h e o c s ~ a l ~ ~ p r e s e n ' t a t i o n .


'1. S. I. Warshaw, Areal Mapping of Arbitrary Plane Regions onto Rectangular
Meshes, ~ m c h1977, UCID-17415 (formerly UCIR-726, August 1973).
2. R. V. Benson, Euclidean Geometry and Convexity, McGraw-Hill, 1966.
3. D. Kershaw, LLL, Private Communication.
4. B. Wendmff, First Principles of Numerical Analysis, Addison-Wesley, 1969.
5. J. T. Martin, R. G. Zwakenberg, S. V. Solbeck,LRLTRAN Language Used with
the CHAT and STAR Compilers, LTSS Part 111,-Chapter 207, Edition 3,
July 1973.
6. Reference to a company or 'product name does not imply approval or recom-
mendatlon of the pmduct by the University of California or the U.S.
Energy,ResearchE Development Administration to the exclusion of others
that m y be suitable.
7. CDC 7600 Hardware Reference Manual, 1972.
8. G. M. Weinberg, An Introduction to General Systems Thinking, Wiley, 1975.
Thia report waa prepared a8 an account of work
spomored by the UnNed StatesGovernmeat. Neither the
U&ed Stater nor the United States Energy Research
& Dcrelopment A d ~ r a t i o n ,nor any of their
gnployccs, nor any of their contractors, subcontractors.
or their employees, maker any warranty, express or
impUed, or eslumes any legal Habllity or responsibility
for t b accuracy, comphtencslr or ulsfulnea of any
information. apparatus, product or process dirclosed.or
represents that its use would not infdnge
prioatelyowned rights.

Rcfannce to a company or product name does not


bnply approval or recommendation of the produd by
ths U n M t y of California or the U S . Energy b s s c h
& Development Admh6rtration to the axcbicm of
others that may be suithle.

Printed in the United States of Ametiea


Available frm
National Technical Iffformation Service
U.S. Department of Commerce
5285 Port Royal Read
Sptingfiild, VA 2216.1
Price: Printed Cupy 5 : Microfiche 53.00

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

You might also like