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

[f] [PRGM]
[f] [P/R]
[f] [PRGM]

Code:
[STO]  [X<>Y] [STO]  [X<>Y] [Rv] [+] [Rv] [-] [X<>Y] [Rv] [*]  [/] [STO][-] [RCL] [RCL]

[f] [P/R]

REGISTERS USED:

R0: area of the polygon
R1: xi
R2: yi

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. Before to enter the coordinates, you must be press [f][PRGM] and [f] [REGS] to begin in the 1st line of the program and clean all registers, including the STACK (X,Y,Z,T)
5. Enter in order the coordinates, P1, P2...Pn-1,P1 in this way: [X coordinate] [ENTER] [Y coordinate] [R/S]
6. At the end of the last point, P1(0,0) Press [RCL]  to obtain the desired area.

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

[f][PRGM] [f] [REGS]

 [ENTER]  [R/S] *** P1(0,0)
 [ENTER]  [R/S] *** P2(0,3)
 [ENTER]  [R/S] *** P3(3,3)
 [ENTER]  [R/S] *** P4(3,0)
 [ENTER]  [R/S] *** P1(0,0)
[RCL] 

RESULT = 9

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

[f][PRGM] [f] [REGS]

 [ENTER]  [R/S] *** P1 (0,0) (Begin with 0,0)
 [ENTER]  [R/S] *** P2 (0,3)
 [ENTER]  [R/S] *** P3 (3,3)
 [ENTER]  [R/S] *** P4 (3,0)
 [ENTER]  [R/S] *** P5 (0,0) (Close the polygon)
 [ENTER]  [R/S] *** P6 (1,1) (here the order of the points in counter clockwise)
 [ENTER]  [R/S] *** P7 (2,1)
 [ENTER]  [R/S] *** P8 (2,2)
 [ENTER]  [R/S] *** P9 (1,2)
 [ENTER]  [R/S] *** P10(1,1) (close the polygon that generate the hole)
 [ENTER] []0 [R/S] *** P11(0,0) (end with 0,0)
[RCL] 

RESULT=8 squared units

*ADITIONAL COMMENT: You can enter the first point (0,0) press only [R/S], only at the begin 