HP 32SII: area of a polygon by coordinates
12-29-2014, 09:19 PM (This post was last modified: 12-29-2014 09:22 PM by Carlos CM (Mexico).)
Post: #1 Carlos CM (Mexico) Junior Member Posts: 35 Joined: Dec 2013
HP 32SII: area of a polygon by coordinates
Program to calculate the area of a polygon by coordinates

Code:
[LBL] [A] [CLVARS] [INPUT] [N]  [E]  [+/-] [*]  [+] [STO] [I] [LBL] [B] [INPUT] [X] [INPUT] [Y] [Rv] [+] [Rv] [-] [X<>Y] [Rv] [*]  [/] [STO][-][A] [RCL][Y] [RCL][X] [ISG][I] [GTO][B] [VIEW][A] [RTN]

REGISTERS USED:

A: area of the polygon
N: total of points to enter
X: xi
Y: yi

LABELS USED:

A (20 bytes), B (28.5 bytes)

NOTES:

X<>Y is SWAP
Rv is ROLL DOWN

INSTRUCTIONS:

1. The polygon must be in the 1st Cuadrant of Cartesian System
2. Must begin/end with P1(0,0) coordinate
3. The order to enter the coordinates is clockwise to normal figures and counter clockwise if the figure has a HOLE.
4. Enter in order the coordinates, P1, P2...Pn-1,P1 in this way: [X coordinate] [R/S] [Y coordinate] [R/S]
6. At the end of the last point, P1(0,0) the program display the desired area.

EXAMPLE 1.
For example, in a square (3x3=9 squared units):

[XEQ] [A]
N? ***Total of points to enter
 [R/S] *** In this case 5 points
 [R/S]  [R/S] *** P1(0,0)
 [R/S]  [R/S] *** P2(0,3)
 [R/S]  [R/S] *** P3(3,3)
 [R/S]  [R/S] *** P4(3,0)
 [R/S]  [R/S] *** P1(0,0)
A=9 ***AREA OF THE POLYGON

EXAMPLE 2.
Example with a hole at center of the last square:

[XEQ][A]
N? ***Total of points to enter
 [R/S] *** In this case 11 points
 [R/S]  [R/S] *** P1 (0,0) (Begin with 0,0)
 [R/S]  [R/S] *** P2 (0,3)
 [R/S]  [R/S] *** P3 (3,3)
 [R/S]  [R/S] *** P4 (3,0)
 [R/S]  [R/S] *** P5 (0,0) (Close the polygon)
 [R/S]  [R/S] *** P6 (1,1) (here the order of the points in counter clockwise)
 [R/S]  [R/S] *** P7 (2,1)
 [R/S]  [R/S] *** P8 (2,2)
 [R/S]  [R/S] *** P9 (1,2)
 [R/S]  [R/S] *** P10(1,1) (close the polygon that generate the hole)
 [R/S] []0 [R/S] *** P11(0,0) (end with 0,0)
A=8 ***AREA OF THE POLYGON

RESULT=8 squared units