The Museum of HP Calculators


Area of a Polygon for the HP-41

This program is Copyright © 2006 by Jean-Marc Baillard and is used here by permission.

This program is supplied without representation or warranty of any kind. Jean-Marc Baillard and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.


Overview
 

-The following program calculates the area of a polygon  A1 A2 ...... An    where  Ai(xi,yi)  are the n vertices.
-The result is positive if the n points are stored counterclockwise.
 

Program Listing
 

Data Registers:         R00 = n      R01 = x1     R03 = x2   ..........     R2n-1 = xn       ( These  registers are to be initialized before executing "PGA" )
                                                        R02 = y1     R04 = y2   ..........     R2n = yn
Flags: /
Subroutines: /

-Synthetic registers M N O may be replaced by any unused data registers.
 

01  LBL "PGA"
02  RCL 00
03  ST+ X
04  STO M
05  RCL 02
06  RCL IND Y
07  STO O
08  -
09  DSE M
10  RCL 01
11  RCL IND M
12  STO N
13  +
14  *
15  DSE M
16  LBL 01
17  RCL IND M
18  ENTER^
19  X<> O
20  -
21  DSE M
22  RCL IND M
23  ENTER^
24  X<> N
25  +
26  *
27  -
28  DSE M
29  GTO 01
30  2
31  /
32  CLA
33  END

( 56 bytes / SIZE 2n+1 )
 
 
      STACK        INPUT      OUTPUT
           X             /         Area

Example:      The 6 vertices of an hexagon are defined by their coordinates (x,y)
 
 
     xi      -2      -1      2      3      2     -1
     yi       0      -2     -1      1      2      3

-We store these 12 numbers in registers       R01     R03     R05    R07    R09    R11
                                                                   R02     R04     R06    R08    R10    R12            respectively

-Then,       6  STO 00     XEQ "PGA"  >>>>   Area =  16.0000   ( in 2.7 seconds )

Note:

-Execution time is of the order of 43 seconds if n = 100
 

Go back to the HP-41 software library
Go back to the general software library
Go back to the main exhibit hall