Classic Computer Magazine Archive COMPUTE! ISSUE 144 / SEPTEMBER 1992 / PAGE G38

Polygons. (program for computing the parameters of polygons)
by Rowland Medler

There have been many programs published for computing the parameters of triangles, even those that aren't right triangles, but few if any have been published for polygons with more than three sides. In case you don't remember your high school geometry, a polygon is any closed plane surrounded by three or more usually straight sides.

Polygons works with any multisided figure that has four or more sides of equal length. If you know one dimension of the polygon, this program will compute all the other possible parameters.

Typing It In

Polygons is written entirely in BASIC for the 64 or 128 in 64 mode. To help avoid typing errors, enter the program with The Automatic Proofreader; see "Typing Aids" elsewhere in this section. Be sure to save a copy of the program before you exit Proofreader.

Calculating

Simply load and run Polygons and then answer the prompts. Suppose you have an octagon, for example, and you know that each of the eight sides is 5 inches long. Enter this information, and Polygons will compute the diagonal (13.06 inches), the width (12.07 inches), the area (120.71 square inches), and the internal angle (135 degrees). If you know any one of these parameters, Polygons can calculate the others. Of course, diagonals and widths aren't meaningful for polygons with an odd number of sides.

The mathematics is straightforward though probably not of everyday familiarity. If you do architectural design or have a use for plane geometry of this level, the program should save you many hours of calculation,

POLYGONS

AP 0 REM COPYRIGHT 1992 - COMP

UTE PUBLICATIONS INTL LTD

- ALL RIGHTS RESERVED QB 5 PRINTCHR$(5)"{CLR}

{11 SPACES}*** POLYGONS * FQ 10 PRINTCHR$ (158) FK 20 PRINT" {14 SPACES} NEEEEEE

EEM" JA 30 PRINT" {11 SPACES) A N

{10 SPACES} M" FK 50 PRINT" {12 S-FACES} YA=INT

{SPACE} ANGLE T " KC 52 PRINT" AB=DIAGONAL Y<** W

IDTH**> T" JF 55 PRINT" {12 SPACES} Y

{2 SPACES} (A R E E) T" KC 57 PRINT" {13 SPACES} M

10 SPACES}N B" SD 60 PRINT"{14 S-FACES)M

{2 SPACES}SIDE{2 SPACES}

N " KP 70 PRINT"{15 SPACES} EEEEEEE

E" JX 75 PRINTCHR$(5) BD 100 INPUT" NUMBER OF SIDES="

;SI BG 110 IFSI<4THENPRINT"THIS PR

OGRAM REQUIRES 4 OR MOR

E SIDES.":END FK 120 PRINT"I ALREADY KNOW:

ONE ONLY)" SE 130 PRINT"{16 SPACES}1) SID

E#" SH 140 PRINT"{16 SPACES}2) WID

TH" SR 150 PRINT"{16 SPACES}3) DIA

G." AC 160 PRINT"{16 SPACES}4) ARE

A" QP 170 INPUT"CATEGORY NUMBER="

;CA JH 180 IF CA=(1)THEN220:GOTO19

0 KQ 190 IF CA=(2)THEN330:GOTO20 DX 200 IF CA=(3)THEN410:GOTO21

0 FS 210 IF CA=(4)THEN510 DG 220 C=360/SI RP 230 A(180-C)/2 GS 240 INPUT"SIDE DIMENSION

;SD RH 250 R= (SD/SIN(C/(180/[arrow up])))*S

IN(A/(180/[arrow up])) CE 260 IF (SI)/2<>INT(SI/2)THE

NPRINT"DIAG. AND WIDTH

{SPACE}ARE NOT MEANINGF

UL FOR{2 SPACES}ODD"; HJ 270 IF (SI)/2<>INT(SI/2)THE

NPRINT" NUMBERS OF SIDE

S BECAUSE THEY DO NOTPA

SS " ; DS 280 IF (SI/2)<>INT(SI/2)THE NPRINT"THROUGH THE CENT ER.":GOTO310

JA 290 PRINT"DIAGONAL

{7 SPACES}=";:PRINT2*(R AC 300 PRINT"WIDTH{10 SPACES}=

" ;:PRINT2*(SIN(A/(180/[arrow up]

))) * (R) AE 310 PRINT"AREA{11 SPACES}="

;:PRINT (SI)*(SD)*(SIN(

A/(180/[arrow up)))*(R)/2 BD 320 PRINT"INTERNAL ANGLE

;180-(360/SI):GOTO620 BB 330 INPUT"WIDTH{10 SPACES}=

";WD AX 340 IF(SI)/2<>INT(SI/2)THEN

PRINT"YOU CAN'T SAY WID

TH OF ODD SIDED FIGURE.

":END HX 350 H=WD/2 DR 360 C=360/SI/2 JH 370 PRINT"SIDE{11 SPACES}="

;:PRINT2*(H*(TAN(C/(180

/[arrow up] )))) DG 380 PRINT"DIAGONAL

{7 SPACES}=";:PRINT H/C

OS (C/ (180/[arrow up]) ) *2 QM 390 PRINT"AREA{11 SPACES}="

;:PRINT(H*(TAN(C/(180/[arrow up] ))))*H*SI

QJ 400 PRINT"INTERNAL ANGLE

;180-(360/SR):GOTO620 FQ 410 INPUT"DIAGONAL

{7 SPACES}=";DI CS 420 B=360/SI/2 GG 430 A=90-B GM 440 IF(SI/2)<>INT(SI/2)THEN

PRINT"YOU CAN'T DEFINE

{SPACE}WIDTH OR DIAG OF ODD ";

AH 450 IF(SI/2)<>INT(SI/2)THEN

PRINT"[2 SPACES}SIDED F

IGURE.":END EC 460 PRINT"WIDTH{10 SPACES}=

;:PRINT(DI)*SIN(A/(180

/arrow up])) FK 470 PRINT"SIDE(11 SPACES}="

;:PRINT((DI/2)*COS(A/(1

80/[arrow up])))*2 BA 480 AR=((DI)*SIN(A/(180/[arrow up]))

*((DI/2)*COS(A/(1801)[arrow up])

))*SI/2 QJ 490 PRINT"AREA{11 SPACES}="

;:PRINT(AR) HS 500 PRINT"INTERNAL ANGLE

;180-(360/SI):GOTO620 BQ 510 INPUT"AREA{11 SPACES}="

;AR QH 520 AT=AR/SI/2 SH 530 B=360/SI/2 FR 540 A=90-B SA 550 PRINT"SIDE{11 SPACES}="

;2*(SQR(2*AT*TAN(B/(180 /[arrow up]))))

FP 560 IF(SI/2)=INT(SI/2)THEN5

90 CQ 570 IF(SI)/2<>INT((SI)/2)TH

ENPRINT"ODD NUMBER SIDE

S HAS NO WIDTH OR"; PE 580 PRINT" DIAG.{2 SPACES}D

EFINED.":GOTO610 PK 590 PRINT"DIAGONAL

{7 SPACES}=";2*(SQR(2*A T*TAN(B/(180/[arrow up]))))/SIN( B/(180/[arrow up]))

JQ 600 PRINT"WIDTH{10 SPACES}=

".;(SQR(2*AT*TAN(B/(180/

[arrow up] ))))*TAN(A/(180/[arrow up]))*2 RE 610 PRINT"INTERNAL ANGLE

;180-(360/SI) BM 620 INPUT"ANOTHER PROBLEM

A) , HARDCOPY (H) OR

{4 SPACES}QUIT (Q)";E$ PD 625 IFE$<>"A"ANDE$<>"H"ANDE

<>"Q"THENPRINT"* ONLY [SPACEI'A' OR H' OR Q ":GOTO620 EQ 630 IFE$="A"THENGOTOO JP 640 IFE$="H"THENGOSUB60035 BK 650 IFE$="Q"THENPRINTCHR$(3 0) :PRINT"{CLR}* THANKS. I'D BE GLAD TO HELP AG AIN * ":END

HC 60035 A$="":OPEN4,4:Z=1023:

FORY=OTO24:FORX=0TO39

: Z=Z+1 FS 60040 CH=PEEK(Z):IFCH>128TH ENCH=CH-128 PE 60050 IFCH<32ORCH>95THENCH= CH+64:GOTO60070 RK 60060 IFCH>63ANDCH<96THENCH =CH+32 SH 60070 A$=A$+CHR$(CH):NEXT:P RINT#4,A$:A$="":NEXT: CLOSE4

Rowland Medler devised this program when an architect requested the length of an eight-sided auditorium whose area was 10,000 square feet. Medler is 74 years old and lives in Gainesville, Florida.