Chapter 20 Geometry

Chapter 20 Geometry

CHAPTER 20 Geometry Most of the programs in this chapter are designed for operations on convex sets in the plane. They were originally written in A...

875KB Sizes 3 Downloads 162 Views

CHAPTER

20

Geometry

Most of the programs in this chapter are designed for operations on convex sets in the plane. They were originally written in APL/360 by A. Tam and R. A. Vitale and were recently modified by G. Podorowsky. The modification was necessary to convert the code to VS APL. More importantly, some of the algorithms were replaced by fast ones, improving the speed of the programs considerably. They deal with convex, bounded closed polygons. The polygons are represented in three ways: (1) Raw form: If the polygon has n faces (n vertices), the raw form is a 2 x n matrix of vertices in counterclockwise order, with X values in the first row and Y values in the second row (the choice of initial vertex is immaterial). For example, a triangle with vertices at (- l,O), (0.5,0), and (- 1,l) would be represented as -1

RAWFORM

0 0.5

-1

(2) Standard form: a 3 x n matrix. The first two rows list the vertices in counterclockwise order as in the raw form. However, the initial vertex must be chosen as follows: Choose the vertex with the smallest Y value; if there is more than one, choose the one that has the smallest X value. The third row contains a list of angles A,, where Aj is the angle to the horizontal of the vector (X,,, , Yj+l) - (X,, Y3)and, f o r j = n , of the vector ( X I ,Yl) - ( X , ,Y,). NOTE

0 5 A1 < A2 < . . . < 2rr. For the same triangle as above, the representation would be

STANDARDFORM

0

-1

1.3258

355

0.5 -1 1 0 3.7296 5.4978

356

20.

GEOMETRY

(3) Support form: The support function of a polygon is given by s(A) = max X cos(A) + Y sin(A),

( X , Y ) a vertex

In support form we shall use as the first row the (signed) distance from the origin to the line that contains a face. The second row will be angles 0 < B l < B2 < * * < 2~ that correspond to the normals. SUPPoRTFoRM

0.5547 0.7071 1 0.24254 2.1588 3.927 6.0382

An experimenter who plans to carry out large experiments is advised to consult Shamos (1976) for faster algorithms. The following programs are adequate for small and moderate sizes of the experiment. We also include a few programs with an entirely different purpose: to compute objects in a Riemannian geometry. In particular, one of these programs calculates geodesic curves.

Function Names: ADDC and ADDCl EXTERNAL DOCUMENTATION

Both of these functions are designed to add convex sets in the sense of Minkowsky addition

c, + CZ

= {z =

z1

+ 22121 E c1, z2 E CZ)

ADDC adds two convex sets while ADDCl adds an arbitrary number of sets with the same number of vertices.

WARNING The algorithm is fairly slow; faster ones can be designed. INTERNAL DOCUMENTATION FOR ADDC

S Y N T A X : K + K l ADDC K 2 P U R P O S E : TO A D D T W O CONVEX POLYGONS INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST U P D A T E : 3 / 8 / 0 0 L E F T ARGUMENT': K 1 : A CONVEX POLYGON, I N STANDARD F O R M

Function Names: ADDC and ADDCl

357

RIGHT ARGUMENT: K 2 : A CONVEX POLYGON, I N STANDARD FORM R E S U L T : K : A CONVEX POLYGON, ALSO I N STANDARD FORM CODE FOR ADDC

r11

c21 C3l C41

C5I

C6l C71 C81

C9l

ClOI

INTERNAL DOCUMENTATION FOR ADDC1

SYNTAX: KtADDCl F I G PURPOSE: TO ADD ANY NUMBER O F POLYGONS W H I C H HAVE THE SAME NUMBER OF V E R T I C E S INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST U P D A T E : 3 / w a o RIGHT ARGUMENT; F I G : A STACKED STANDARD FORM ARRAY R E S U L T : K:STANDARD FORM SUM O F POLYGONS I N FIG CODE FOR ADDC1 V K t A D D C l F I G ; D ; D X ; DY ; F ; A ; B ; M A X ; I ;

KK;N [l]

D+(~$F)-F+FIGCBC&B+(-~+~XIN),(-~+~ x~N+(pFIGC;11)+3)1;1

20.

358

GEOMETRY

Function Name: AREA EXTERNAL DOCUMENTATION PURPOSE

To compute the area of a convex polygon given in raw or standard form. INTERNAL DOCUMENTATION

S Y N T A X : A+AREA P PURPOSE: TO FI-ND THE A R E A OF P INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E L A S T UPDATE: 3 / 8 / 8 0 R I G H T ARGUMENT: P : A CONVEX POLYGON, I N E I T H E R RAW OR STAILrDARD FORM R E S U L T : A : A R E A OF P CODE

[I]

V A+AREA P ; X ; Y AtO.5xVADD(Xxl~Y>,-(Y~P[2;I)Xl~X~~CI;I V

Function Name: ATAN

359

Function Name: ATAN

EXTERNAL DOCUMENTATION

PURPOSE

To compute the angle between two straight lines. One line given by two points on, the other line horizontal through given point. INTERNAL DOCUMENTATION

S Y N T A X : A+XOYO ATAN XY P U R P O S E : TO COMPUTE THE ANGLE BETWEEN THE L I N E THROUGH XOYO AND X Y AND THE P O S I T I V E H O R I Z O N T A L THROUGH XOYO INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST U P D A T E : 3 / 8 / 8 0 L E F T ARGUMENT: X O Y O : THE COORDINATES O F THE O R I G I N A L REFERENCE P O I N T ( A VECTOR O F LENGTH 2) R I G H T ARGUMENT: X Y : 2 x N M A T R I X OF P O I N T S NOT C O N T A I N I N G XOYO R E S U L T : A : VECTOR O F LENGTH N , C O N T A I N I N G FOR EACH P O I N T O F X Y , THE ANGLE BETWEEN THE L I N E THROUGH XOYO AND THAT P O I N T , AND THE P O S I T I V E H O R I Z O N T A L THROUGH XOYO CODE

El1

c21 C31 C4l C5I

Q A t X O Y O ATAN X Y ; X ; Y ; D X ; D Y X+XYC1;1 Y+XYC2;1 DX+X-XOYO[l] DY+Y-XOYOC21

A+ -((O(DY=O)~DX+(DY*O)X(OI-O.~XDY) - 3ODX+DYtDY=O) V

20.

360

GEOMETRY

Function Names: AXF and CIRCUM EXTERNAL DOCUMENTATION

PURPOSE To compute a rectangle circumscribing a given polygon, and to circumscribe a polygon by one with given angles. INTERNAL DOCUMENTATION FOR AXF

SYNTAX: FENCEtAXF F P U R P O S E : TO C I R C U M S C R I B E A CONVEX POLYGON BY A RECTANGLE INDEX O R I G I N : 1 AUTHOR: A . T A R R Y R . A . V I T A L E LAST U P D A T E : 3/8/80 R I G H T ARGUMENT: F : A CONVEX POLYGON, I N RAW OR STANDARD FORM R E S U L T : F E N C E : STANDARD FORM RECTANGLE C I R C U M S C R I B E D ABOUT F ; T H E S I D E S OF FENCE A R E O R I E N T E D W I T H THE A X E S CODE FOR AXF

[l] C2I

V FENCEtAXF F;MX;MY;XM;YM ~(((pF[2;])=2)A(F[l;l]=~[l;2])vF[2;1]= F[2;2l)/LN FENCE+ 3 4 pMX,XM,(XM+T/PCl;l>,(MX+L/F ~1;]),MY,(~Y+~/F~2;l)yYMy(Y~+~/F~2;l)y

00,0.5,1,1.5 c31

-+o

[ 4 l LN:FENCE+STFORM F V

INTERNAL DOCUMENTATION FOR CIRCUM

S Y N T A X : FENCE+ P H I CIRCUM F I G P U R P O S E : TO C I R C U M S C R I B E A POLYGON WITH G I V E N FACE ANGLES ABOUT ANOTHER CONVEX POLYGON

Function Names: DCNP, DECOMP, DEQUAD

361

INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST U P D A T E : 3/8/80 L E F T ARGUMENT: P H I : T H E VECTOR O F FACE ANGLES R I G H T ARGUMENT': F I G : THE POLYGON TO BE C I R C U M S C R I B E D , I N STANDARD FORM R E S U L T : F E N C E : POLYGON C I R C U M S C R I B E D ABOUT FIG WITH FACE A N G L E S P H I ; I N STANDARD FORM CODE FOR CIRCUM

C11

Q F E N C E c P H I CIRCUM F I G ; S F E N C E t P O L Y P H I SUPPORT S F A C B F I G V

Function Names: DCNP, DECOMP, DEQUAD

EXTERNAL DOCUMENTATION

PURPOSE These functions perform triangulation of convex figures. NOTE For special cases the user should rotate figure first (to avoid domain error) and then rotate back.

If a convex polygon has two parallel sides, it is the sum of a degenerate polygon (a line segment) and another polygon. Those line segments should be removed before using programs. INTERNAL DOCUMENTATION FOR DCNP

SYNTAX: TRtDCNP F I G P U R P O S E : TO F I N D A S E T O F T R I A N G L E S WHOSE SUM I S SOME T R A N S L A T I O N OF A G I V E N POLYGON (WHICH HAS NO P A R A L L E L S I D E S ) INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E

20.

362

GEOMETRY

LAST UPDATE: 5 / 2 o / a o R I G H T ARGUMENT: F I G : THE O R I G I N A L POLYGON, I N STANDARD FORM; THE POLYGON MUST HAVE NO PARALLEL S I D E S R E S U L T : T R : STACKED STANDARD FORM ARRAY OF T R I A N G L E S SUCH THAT T H E I R S U M I S SO44E T R A N S L A T I O N OF THE O R I G I N A L F I G U R E NOTE: THERE A R E ( ( N U M B E R OF S I D E S OF F I G ) - 2 ) TRIANGLES CODE FOR DCNP

V T R t D C N P F;T;I;J;L;RF;TH;X;Y;C;D; C l ]

123 C31 [: 4 1

C5l C6l [71 C81 C9l

[lo] [ill

A;MIN;S TR+ 0 3 p 0 LP:+((pF)C21=3)/END I~(L=MINtL/L)/~pL~((((lC$~Cl;I)-FC1;1) *2)+((1C$F[2;]>-FC2;I)*2)*0.5 RF+( -A+FC3 ; I C 1 ] 1 ) R O T A T E F X+RFC1;1 YtRFC2;I THtRFC3;I J+( Y = r / Y 1 / I P Y

XCJl+(C+XCJ1)tMINxS~(((3OTH~Jl~S

~XCJ]#XC(lC$~pX)CJII)~(3O~HCJ-lI))-l

YCJI+(D~YCJI)~(S~(~OTHCJIXS)X(XCJI-C)) - 1 ( - S ) x M I N t 3 0 ( THC J - 1 1 - 0 0 . 5 T R + T R , C l I T t A ROTATE 3 3 p X [ J I , ( M I N + X

CJ]),C,YCJI,YCJI,YCJI,D,O,~H~J-lI,TH~J~

C123 X C 1 + 2 J - 2 ] t X C 1 + 2 J - 2 I - M I N [ 1 3 1 F+A R O T A T E 0 1 + ( 3 , p X ) p X , Y , T H C 1 4 1 +LP 1151 END:TR+TR,[lI F

v

INTERNAL DOCUMENTATION FOR DECOMP

S Y N T A X : TRtDECOMP F I G PURPOSE: TO DECOMPOSE A CONVEX POLYGON I N T O T H E SUM OF T R I A N G L E S ( A N D / O R L I N E S E G M E N T S ) INDEX O R I G I N : 1

Function Names: DCNP, DECOMP, DEQUAD

363

AUTHOR: A. TARR, R.A. VITALE LAST UPDATE: 3 / 8 / 8 0 RIGHT ARGUMENT: FIG: THE ORIGINAL POLYGON, IN STANDARD FORM WITH NO. PARALLEL SIDES. RESULT: TR: STACKED STANDARD FORM ARRAY OF TRIANGLES (AND/OR LINE SEGMENTS) SUCH THAT THEIR SUM IS THE ORIGINAL FIGURE CODE FOR DECOMP

Q TRtDECOMP FIG;A;C;D;F;H;I;II;J;L;

LI;LIJ;LJ;N;Q;TAN;U;V;W;S;X;Y;T C11 F+FIG C21 TR+ 0 3 p 0 C31 H+TAN[Q+~TAN+3OFIGC3;11 chi + ( O = + / V + ~ E ~ 1O(I@H)-H)/CALL > C5l C+V/ipV C6l I+&CClL&CCtlI C71 J+&CClrQCCtll [8] Lt((((l~X)-XtFlGCl;l)*2)+((l~Y)Y+PIG[2;])*2)*0.5 I p U+LCIl =LCJ 1 LIJ+U/ C 91 [lo1 L+V/ i p V+LCIl>LCJ 1 C 111 LJ+W/ I p W+L C I1pX,Y,FIGC3;1 C 2 3 1 +(3>(pF)C21/FUDGE C241 CALL:TR+TR,[l] DCNP F C 2 5 1 F U-D G E : ~ t ( ( ( t / T R C ( l + N ) ; l l ) , ( t / T ~ C ( 2 t N ~ 3 x lttN);l]))-FIGCl 2 ;l])+N+(pTR)ClI+S

20.

364

[26] C271

GEOMETRY

TR[(l+N);]+TR[(l+N);I-D[1I !i"RC(2-tN);]+TRC(2+N);I-DC2I

V

INTERNAL DOCUMENTATION FOR DEQUAD

S Y N T A X : T R I t D E Q U A D QUAD P U R P O S E : TO DECOMPOSE A Q U A D R I L A T E R A L I N T O THE S U M OF T R I A N G L E S ( A N D / O R L I N E S E G M E N T S ) INDEX O R I G I N : 1 AUTHOR : A . T A R 3 , R . A . V I T A L E LAST U P D A T E : 3 / 8 / 8 0 R I G H T ARGUMENT: QUAD: THE Q U A D R I L A T E R A L , I N STANDARD FORM R E S U L T : T R I : STACKED STANDARD FORM A R R A Y OF T R I A N G L E S ( A N D / O R L I N E S E G M E N T S ) SUCH THAT T H E I R SYM I S QUAD CODE FOR DEQUAD Q T R I t D E Q U A D Q U A D ;N ; V ; T A N ; T H ; X ; Y ; W ;

c11

c21 131 C41

C51 C6I C71 C81 C9l

ClOl Clll C121 C131 C141 C151 El61

C;MIN;Tl;T2;L;Q;B;R;S;T;D;I;J;H

TAN+3OTH+QUADC 3 ;1 X t Q U A D C l ;1 YtQUADC2;I

+ ( ( O = N ) , l = N + + / W + l E - l O ~ ~ T A N [ l2 l - T A N C 3

41)/ZEROYONE t PARALLELOGRAM' T I + 3 2 pXC1l,XC2l,YC1I,Y~21,T~~lI~THC~I T2+ 3 2 p X C l l , X C 4 1 , Y C 1 1 , Y c 4 1 ,THE21 ,THC41 +FUDGE 0NE:'TRAPEZOID' I+W/ 1p C + ( L = M I N + L / L ) / ~ ~ L ~ ( ( ( ( ( ~ ~ ~ ) - ~ ) * ~ (((l+Y)-Y)*2>>*0.5>CI,1+21 Q+(-ltJ+,(2 2 pt4)[C;11)Cbl4 Tl+Tl[;l],Tl+(3 2 pXCJlyXCQC2II, Y [ J 1 , Y C Q C 2 1 1 ,H 1 I: ;QH+( THC J I ,THC Q C 3 1 1 1

w

~~TH~~C2ll,TH~QC311,TH~Q~~~~ NtMINt(ltTANCI1*2)*0.5 T2+(3 3 p X C J l , ( X C ~ C 3 1 1 + N ~ ~ X C & c 4 1 1 -

XCQC3ll),XC&C4ll,YCJl~~YC~~3~~~

Function Names: DIST, DISTANCE, DISTPT

365

Function Names: DIST, DISTANCE, DISTPT EXTERNAL DOCUMENTATION PURPOSE

The functions DIST and DISTPT compute HausdorE distances between convex sets and between a point and a convex set. The auxiliary function distance is called by DIST. WARNING

The program is fairly slow for a large number of vertices; faster algorithms exist. INTERNAL DOCUMENTATION FOR DIST

SYNTAX: D+Kl DIST K 2 PURPOSE: TO COMPUTE THE HAUSDORFF DISTANCE BETWEEN K 1 AND K 2

20.

366

GEOMETRY

INDEX ORIGIN: 1 AUTHOR : A. TARR , R . A. VITALE LAST UPDATE: 5 / 2 0 / 8 0 LEFT ARGUMENT: K 1 : A POLYGON, IN STANDARD FORM RIGHT ARGUMENT':K 2 : A POLYGON, IN STA NDA R D FORM RESULT: D : THE HAUSDORFF DISTANCE BETWEEN K 1 AND K 2 CODE FOR DIST [ 11

V D+Kl DIST K 2 D+T I ( K 1 DISTANCE K 2 ,K2 DISTANCE K 1 V

CODE FOR DISTANCE

c11 c21 C3l C4l

C51 r61

"71 C81 C9I c101

Clll 1121

Function Names: GEODESIC, CHRISTOFFEL, GEOAUX

367

INTERNAL DOCUMENTATION FOR DISTPT

S Y N T A X : D t K D I S T P T PT P U R P O S E : TO F I N D THE HAUSDORFF D I S T A N C E BETWEEN A P O I N T AND A POLYGON INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST UPDATE: 5 / 2 0 / 8 0 L E F T ARGUMENT: K : A POLYGON, I N RAW OR STANDARD FORM R I G H T ARGUMEIVT: P T : A VECTOR OF LENGTH TWO; THE POINT ( X , Y > R E S U L T : D : THE MAXIMUM D I S T A N C E FORM PT TO A VERTEX OF K

CODE FOR DISTPT

Function Names: GEODESIC, CHRISTOFFEL, GEOAUX EXTERNAL DOCUMENTATION

PURPOSE

To compute geodesics for Riemannian geometry on an N-dimensional manifold. This is done by the function GEODESIC, which is supported by CHRISTOFFEL, which computes the Christoffel symbol of the second kind, and the auxiliary function GEOAUX, which sets up the differential equation for the geodesics. For S = arclength the O.D.E. can be written as d2xi -

-c 5.k

C'k)

d x j dxk --

ds ds

where the 3-array in curly brackets is the Christoffel symbol.

20. GEOMETRY

368 The Christoffel symbol

requires the metric tensor G = {gir}and its partial derivatives. The program uses the convention that in this 3-array the first axis stands for the subscript corresponding to the variable w .r.t. which differentiation is performed. Also, in the 3-array representing the Christoffel symbol, the first axis stands for the upper of the three subscripts. To solve the O.D.E., the main problem called KUTTA; see Chapter 3. REFERENCES Sokolnikoff, I. S. (1951). “Tensor Analysis,” (Section 58). Wiley, New York. Graustein, W. (1951). “Differentia1 Geometry,” (Section 68). Dover, New York . INTERNAL DOCUMENTATION FOR GEODESIC

S Y N T A X : GEODESIC PURPOSE: T O COMPUTE G E O D E S I C S FOR R I E M A N N I A N GEOMETRY INDEX 0 R I G I N : I AUTHOR: U. GRENANDER LAST U P D A T E : I O / 8 0 N 0 T E : C A L L S F U N C T I O N S KUTTA AND C H R I S T O F F E L AND GEOAUX U S E R MUST S U P P L Y TWO F U N C T I O N S . ONE THAT HAS THE M E T R I C T E N S O R A S E X P L I C I T R E S U L T , THE OTHER ONE THE D E R I V A T I V E S OF THE M E T R I C TENSOR CODE FOR GEODESIC

[I1 C23

C3l

C41

V GE0DESIC;XO;VO;STEP;S RCOMPUTES G E O D E S I C S FOR R I E M A N N I A N RGEOMETRY R C A L L S F U N C T I O N S GEOAUX, C H R I S T O F F E L RAND KUTTA ’WHAT I S D I M E N S I O N OF S P A C E ? ‘ Nl4O

Function Names: GEODESIC, CHRISTOFFEL, GEOAUX c51 [Sl C71 C81 C91 ClOI c111

c121 C131

C141

Cl5l Cl61 C17 I C181

'WHAT I S COMPUTES G4-1 'WHAT I S COMPUTES TENSOR? ' GPRIMEtC] 'WHAT I S XO+O ' WHAT I S

369

NAME OF FUNCTION THAT METRIC TENSOR? ' NAME O F FUNCTION THAT DERIVATIVES OF METRIC STARTING POINT?' VECTOR O F S T A R T I N G D I R E C T I O N ? '

vo+o VO+VQ+(VOt.x(mG,' 1,vXO)+.xVO)*0.5 ' WHAT I S D E S I R E D S T E P S I Z E ? '

STEP43 'WHAT I S D E S I R E D T O T A L ARC LENGTH?'

s+o

RES+' GEOAUX' V

KUTTA 0 ,XQ , V Q , S T E P , S

INTERNAL DOCUMENTATION FOR CHRISTOFFEL

S Y N T A X : Z + M C H R I S T O F F E L MPRIME P U R P 0 S E : C O M P U T E S C H R I S T O F F E L SYMBOL OF SECOND K I N D FOR R I E M A N N I A N GEOMETRY INDEX 0 R I G I N : l AUTHOR: U . GRENANDER L A S T UPDATE : 1O / 8 Q L E F T ARGUMENTzMETRIC T E N S O R R I G H T ARGUMENT: 3 - A R R A Y OF P A R T I A L D E R I V A T I V E S OF METRIC TENSOR R E S U L T : C H R I S T O F F E L SYMBOL A S 3 - A R R A Y CODE FOR CHRISTOFFEL Q Z+M C H R I S T O F F E L MPRIME c 1 1 RCOMPUTES C H R I S T O F F E L SYMBOL OF THE ASECOND K I N D C21 A M I S METRIC TENSOR C 3 l fl MPRIME I S T E N S O R OF D E R I V A T I V E S OF A M WITH F I R S T

370

20.

GEOMETRY

C 4 1 R S U B S C R I P T FOR S U B S C R I P T OF INDEPENDENT C 5 1 R V A R I A B L E W . R . T . WHICH D I F F E R E N T I A T I O N IS A PERFORMED C S l R I N RESULT ( 3 - A R R A Y ) F I R S T A X I S I S C 7 1 A S U P E R S C R I P T I N C H R I S T O F F E L SYMBOL C81 Z t 0 . 5 ~ ( 8 M ) t . x ( 31 2 Q M P R I M E ) t ( 3 2 1 QMPRIME)-MPRIME

V INTERNAL DOCUMENTATION FOR GEOAUX

S Y N T A X : ZtGEOAUX Y P U R P 0 S E : A U X I L I A R Y FUNCTION THAT COMPUTES R I G H T HAND S I D E FUNCTION I N O . D . E . FOR FUNCTION G E O D E S I C R I G H T ARGUMENT: VALUE OF DEPENDENT V A R I A B L E S AND T H E I R D E R I V A T I V E S R E S U L T : F U N C T I O N V A L U E S O N R I G H T HAND S I D E OF THE 0 . D . E CODE FOR GEOAUX r11

C21 C3l [4]

C51

Q Z t G E O A U X Y ;CHRISPOFF Yt1J.Y Zt(2xNl)pO ZCtNll+YCNlttN11 CHRISTOFF+(aG,' ' , v Y C t N l I ) CHRISTOFFEL aGPRIME,' ' , v Y C t N l I

~CN~+~N~I+-(CHRISTOFF~.XY~N~~I~V~]

t.xY[Nl+tNl] V

Function Name: HULL1 EXTERNAL DOCUMENTATION PURPOSE

Calculates the convex hull of given set of points in the plane.

Function Name: HULL1

371

NOTE

See Shamos (1976) for discussion of algorithms. INTERNAL DOCUMENTATION

SYNTAX: Z+HULLl X PURPOSE: TO FIND THE CONVEX HULL OF A SET OF POINTS INDEX ORIGIN: 1 AUTHOR: G. PODOROWSKY LAST UPDATE: 5 / 1 8 / 8 0 RIGHT ARGUMENT: X : THE SET OF POINTS, IN EITHER RAW OR STANDARD FORM RESULT: Z : THE POINTS ON THE CONVEX HULL OF X , IN RAW FORM CODE

V ZtHULLl X;COUNTl;MINY;MINS;RS;THETS;

c11 C21 C31 C41 CS!

C6l C71 [83 C91 El01

[ill c121 t131 C141 El51 C161

XI;X2;COUNT2;ZER;T;TT;I X+XCl 2 ; I COUNTl+pXCl;I MINY+L/XC2;1 +(l<+/MINY=X[2;])/FIND MINS+XC;XC2;1iMINYl REMIN:MINS+Q((pX)[21,2)pMINS X+X-MINS RS+t f X* 2 +((t/XCl;l~O)~l)/ZEROS THETS+XC2;1:XC1;1 LINK:X+(X,[11 THETS),Tl! RS Xlt((THETS2O)AO#tfXCl 2 ; I ) / X X2+(THETS
[17] LP:~((xc3;2]=x[3;31)A(O#x[3;2])A(l#(xr3; C181

23=9999)AO=t/XCl;l
I(X~~;~]-X[~;~])~(X[~;~I-X[~;~I)

372

20.

GEOMETRY

C 1 9 1 X-+l@X c 2 0 1 +((,XCl 2 ; I l l * 0 O)/LP C 2 1 1 COUNT2+pX[1;1 1 2 2 1 +(COUNT2=COUNTl)/END C 2 3 1 COUNTl-+COUNT2 C 2 4 1 +LP C 2 5 1 END;X+X[l 2 ;]+MINS+(2,TT)p((TTpMINS

[263 C271

Cl;l),((rTt(pX.>C2I>pMINSC2;I)) Z+X

+O

[28] DROP:XtX[;T-+(T#2)/T+~(pX)[2]~ [291 +LP [30] F I N D : M I N S c ( L I X C l ; ( X C 2 ; I ~ ~ I N Y ) / ~ p X C 2 ; ] 1 ) , MINY C313 +REMIN C321 ZEROS:ZER+(XC~;IEO>/I~XC~;I C 3 3 1 DUM+XCl;I [ 3 4 1 D lPM C Z ER 1+-1 C 3 5 1 THETS+X[2 ;]+DUM C 3 6 1 THETSC ZERlt9 9 9 9 C371 +LINK C 3 8 1 SAME:OUT+ltXC4; 2 311L/X[4; 2 3 1 C391 X ~ X C ; I ~ ~ ~ ~ O U T l / I + i ( p X ~ C 2 1 1 C401 +LP V

Function Name: LINSERIES EXTERNAL DOCUMENTATION

PURPOSE To calculate a Minkowsky polynomial of a given convex polygon. INTERNAL DOCUMENTATION

SYNTAX: KSTAR+L LINSERIES K PURPOSE: TO COMPUTE THE 'POLYNOMIAL' DESCRIBED BELOW INDEX ORIGIN: 1 AUTHOR: A. TARR, R .A. VITALE LAST UPDATE:3 / 8 / 8 0

Function Name: MATRANS

373

LEFT ARGUMENT: L : A 2 x 2 MATRIX RIGHT ARGUMENT: I(: A CONVEX POLYGON, I N STANDARD FORM R E S U L T : K S T A R : A POLYGON I N STANDARD FORM SUCH THAT : 2 N K S T A R = K + LK t L K t t L K NOTE: PROGRAM W I L L ASK USER FOR MAX POWER N

...

CODE V KSTAR+L

[21

LINSERIES K;N;MAT;I ' H O W FAR SHOULD SUM GO - - MAX POWER OF L ? ' N4I

c31

I t 0

C11

C41

MAT+K C51 LP:I+It1 MAT+MAT,C13 L MATRANS M A T C ( - 2 + 3 x I ) , c6! (-1t3XI);l +( I < N ) / L P C71 K S T A R t A D D C l MAT C81 V

Function Name: MATRANS EXTERNAL DOCUMENTATION

PURPOSE Calculates linear transformation of given convex polygon in standard form. INTERNAL DOCUMENTATION

S Y N T A X : XY+M MATRANS P PURPOSE: TO COMPUTE AN A R B I T R A R Y L I N E A R TRANSFORMATION O F A CONVEX POLYGON INDEX ORIGIN: 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST UPDATE: 3 / 8 / 8 0

20.

374

GEOMETRY

L E F T ARGUMENT: M : A 2 x 2 M A T R I X , THE L I N E A R OPERATOR R I G H T ARGUMENT: P : THE CONVEX POLYGON, I N STANDARD FORM R E S U L T : X Y : T H E TRANSFORMED F I G U R E ( M P ) , I N STANDARD FORM CODE

C11

c21 C3l C41

C5l C6l C71

C8I 191

Q XY+M MATRANS P ; T ; C ; Z ; D E T ~ ( O = ~ E T ~ ( M C ~ ; ~ I ~ M C ~ ; ~ ~ ) - M C ~ ; ~ I /SING T+Mt.xP[l 2 ;] +(DET>O)/OK T+@P O K : XYtSTFORM T +O SIN~:C+(~((C~11*2)t(CC21*2))*0.5)~C+M[(lt

~/0=MC1;1);1

T+ 2 1 ~ c ~ r / ~ XYtSTFORM T , 2 1 p C x L / Z

~

~

~

V

Function Name: PERlM EXTERNAL DOCUMENTATION

PURPOSE Calculates the perimeter of given convex polygon. INTERNAL DOCUMENTATION

S Y N T A X : Z+PERIM P P U R P O S E : TO COMPUTE THE P E R I M E T E R O F A CONVEX POLYGON OR L I N E SEGMENT INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST U P D A T E : 3/8/80 R I G H T ARGUMENT: P : CONVEX POLYGON OR L I N E

r

i

~

i

Function Names: POL Y , SFACE, STFORM

375

S E G M E N T , I N RAW OR STANDARD FORM R E S U L T : 2: THE P E R I M E T E R OF P N O T E : THE P E R I M E T E R O F A L I N E SEGMENT I S T W I C E THE A P P A R E N T LENGTH CODE

Function Names: POLY, SFACE, STFORM EXTERNAL DOCUMENTATION

PURPOSE Transform support form of given convex polygon to standard form, the inverse, or from raw form to standard form. INTERNAL DOCUMENTATION FOR POLY

S Y B T A X ; V E R T t P O L Y SUP P U R P O S E : TO CONVERT FROM SUPPORT TO STANDARD FORM INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST UPDATE: 3 / 8 / 8 0 R I G H T ARGUMENT: S U P : SUPPORT FORM OF A POLYGON R E S U L T : V E R T : STANDARD FORM R E P R E S E N T A T I O N O F SUP CODE FOR POLY Q V E R T t P O L Y S U P ; X ; Y ; S I N ; C0S;SIND;I ;

J ; A ; S ;P H I

3 76

20.

C1I C2I C31

GEOMETRY

Xt((SCJIxSlNCII)-(SCIIx(SINtloPHI)

[J+l+II))t(SIND+lO(PHI-(1$PHI+SUP c 2 ;1 1 1[I+-t p S+SUPC 1 ;1 1 Y+((S~II~COSCJ])-(S[JIX(COS+~OPHI) CIl))+SINDIIl

VERTt((3,pS)p(-lQX),(-l~Y),~)[;~A+(02) 1PHI+o0.51 V

INTERNAL DOCUMENTATION FOR SFACE

S Y N T A X : S t S F A C E XY P U R P O S E : TO CONVERT TO SUPPORT FORM FROM RAW OR STANDARD FORM INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST U P D A T E : 3 / 8 / 8 0 R I G H T ARGUMENT: X Y : A POLYGON ( O R L I N E S E G M E N T ) I N RAW OR STANDARD FORM R E S U L T : S : SUPPORT FORM R E P R E S E N T A T I O N OF

XY

CODE FOR SFACE

INTERNAL DOCUMENTATION FOR STFORM

S Y N T A X : NEWFtSTFORM F P U R P O S E : TO CONVERT TO STANDARD FORM FROM RAW FORM INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST UPDATE: 3 / 8 / 8 0

Function Name: SUPPORT

377

R I G H T ARGUMENT: F : RAW FORM R E P R E S E N T A T I O N OF POLYGON OR L I N E SEGMENT R E S U L T : NEWF : STANDARD FORM R E P R E S E N T A T I O N OF F CODE FOR STFORM

Function Name: SUPPORT EXTERNAL DOCUMENTATION PURPOSE

For a convex polygon given in support form and for given angles, calculate the values of the support function. INTERNAL DOCUMENTATION

S Y N T A X : S U P t P H I SUPPORT S F P U R P O S E : T O CALCULATE T H E SUPPORT FUNCTION A T ANY G I V E N ANGLES C 0 , 2 P I ) INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V f T A L E L A S T UPDATE: 5 / 1 8 / 8 0 LEFT ARGUMENT: P H I : THE ANGLES A T WHICH SUPPORT FUNCTION I S TO BE EVALUATED ( O N INTERVAL [ 0 , 2 P I ) R I G H T ARGUMENT: S F : SUPPORT FORM R E S U L T : S U P : M A T R I X WITH A N G L E S P H I I N C R E A S I N G I N C 0 , 2 P I ) I N T H E SECOND ROW, W I T H CORRESPONDING V A L U E S OF THE SUPPORT FUNCTION I N THE F I R S T ROW

378

20.

GEOMETRY

CODE

El3

C21 C31 C41

C53 [S]

Q S U P t P H I SUPPORT S F ; I ; J ; I I ; N PHI+PHIC4PHI+-,PHIl I++/PHIo.?SFC2;1 II+(I=O)/IPI ICIIl+N+pSFCl;I J+( 14)I N ) C I 1

SUP+-(~,~PHI)~(((SF[~;I]X~O(SF[~;J] -PHI))+(SFCl;Jlxlo(PHI-SFC2;11)))) +1OSF[2;JI-SF[2;II),PHI Q Function Names: ROTATE, SCALE, TRANS

EXTERNAL DOCUMENTATION

PURPOSE

Applies Euclidean transformations to convex polygon given in standard form. INTERNAL DOCUMENTATION FOR ROTATE

S Y N T A X : RF+T ROTATE F I G PURPOSE: TO COMPUTE THE R O T A T I O N O F A POLYGON INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST U P D A T E : 3/8/80 L E F T ARGUMENT: T : ANGLE THROUGH WHICH F I G U R E I S TO BE ROTATED ( T I S I N R A D I A N S ) R I G H T ARGUMENT: F I G : POLYGON TO BE R O T A T E D , I N STANDARD FORM R E S U L T : R F : THE ROTATED POLYGON, I N STANDARD FORM CODE FOR ROTATE

C 11

Q RF+T R O T A T E F I G ; A A+-(02 ) I FIGC 3 ; 1 + T

Function Names: ROTATE, SCALE, TRANS

379

INTERNAL DOCUMENTATION FOR SCALE

S Y N T A X : NEW+N S C A L E OLD P U R P O S E : TO S C A L E POLYGONS BY AN A R B I T R A R Y S C A L I N G CONSTANT INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST UPDATE: 3 / 8 / 8 0 L E F T ARGUMENT: N : A S C A L I N G CONSTANT R I G H T ARGUMENT: O L D : P O L Y G O N ( S ) T O BE S C A L E D , I N ( S T A C K E D ) STANDARD FORM ARRAY R E S U L T : NEW: OLD S C A L E D BY N ( E A C H POLYGON I N OLD I S SCALED BY N CODE FOR SCALE Q NEW+N

[11 C23

SCALE 0 L D ; R

~LD~(l+R),(2+R>;~+OLD~(ltR),(2tR+3~~1 t1(pOLD)Cllt3);lxN NEWtOLD Q

INTERNAL DOCUMENTATION FOR TRANS

S Y N T A X : NEWF+V T R A N S F I G P U R P O S E : TO T R A N S L A T E A F I G U R E I N X A N D / O R Y DIRECTIONS INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST U P D A T E : 3 / 8 / 8 0 L E F T ARGUMENT: V : VECTOR OF A X , AY THROUGH WHICH F I G U R E I S TO BE T R A N S L A T E D R I G H T ARGUMENT: F I G : STANDARD FORM OF F I G U R E TO B E T R A N S L A T E D

20.

380

GEOMETRY

R E S U L T : NEWF: T R A N S L A T E D F I G U R E , I N STANDARD FORM CODE FOR TRANS

[I]

v

NEWFcV T R A N S F I G

NEWF+(pFIG)p(FIGCl;I+l+,V),(FIG[2;1 +-1+,V ) , F I G [ 3 ; 1 V

Function Name: RMVFVT EXTERNAL DOCUMENTATION

PURPOSE Cleans given representation of convex polygon in standard form by removing false vertices. INTERNAL DOCUMENTATION

S Y N T A X : X Y T H t R E M F V T UV PURPOSE: T O REMOVE ANY F A L S E V E R T I C E S F R O M A POLYGON R E P R E S E N T A T I O N INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST U P D A T E : 3 / 8 / 8 0 R I G H T ARGUMENT: U V : A COMPLEX POLYGON, I N STANDARD FORM R E S U L T : X Y T H : E S S E N T I A L L Y THE SAME POLYGON, BUT WITH ANY F A L S E V E R T I C E S REMOVED N O T E : F A L S E V E R T I C E S A R I S E MOST OFTEN I N THE A D D I T I O N OF CONVEX F I G U R E S I N WHICH A S I D E OF ONE I S P A R A L L E L TO A S I D E OF THE OTHER CODE

c11

C21

V XYTHtREMFVT U V ; W ; N W+(N+pUVC 3 ; 1 > p 1

W C ( U ~ ~ 3 ; l = ~ l ~ U ~ C 3 ; 1 ) / ~ N l + O

Function Name: VADD C3l

38 1

XYTH+W/UV V

Function Name: VADD

EXTERNAL DOCUMENTATION

PURPOSE

To achieve high accuracy in adding the elements of a numeric vector. INTERNAL DOCUMENTATION

SYNTAX: ZtVADD V P U R P O S E : TO ADD THE ELEMENTS O F THE VECTOR V INDEX O R I G I N : 1 AUTHOR: A . T A R R , R . A . V I T A L E LAST U P D A T E : 5 / i a / a o R I G H T ARGUMENT: V : A VECTOR R E S U L T : Z : A S C A L A R , THE SUM O F THE ELEMENTS OF V NOTE: TO O B T A I N M I N I M U M E R R O R , V I S S E P A R A T E D I N T O P O S I T I V E AND N E G A T I V E TERMS AND THEN ADDED THE S M A L L E S T ELEMENTS I N A B S O L U T E VALUE F I R S T CODE