hp41programs

polyhedron

Volume and Area of a Polyhedron for the HP-41


Overview
 

 1°)  Volume
 2°)  Volume & Area
 3°)  Volume & Area of a Convex Polyhedron inscribed in a Sphere
 

-In paragraphs 1°) & 2°)  we assume that the coordinates of all the vertices are known.
-In paragraph 3°) all the edges lengths are given.
 

1°)  Volume
 

-The polyhedron is defined by its n vertices V1(x1,y1,z1) , .......... , Vn(xn,yn,zn)  and  f  faces.
-Each face has to be determined by its vertices, seen counterclockwise from outside the polyhedron.

-The polyhedron is divided in several tetrahedrons and a sum of determinants of order 3 gives the volume.
-Likewise, the area is obtained by a sum of norms of cross-products.
-The position of the origin of the coordinates doesn't change the results,
 and these programs also work if the polyhedron is not convex.
 
 

Data Registers:       •  R00 = n.fff = n + f /1000                                 ( These  registers are to be initialized before executing "PHV" )

                                  •  R01 = x1   •  R04 = x2   ..........   •  R3n-2 = xn         •  R3n+1 =  vertices of face 1
                                  •  R02 = y1   •  R05 = y2   ..........   •  R3n-1 = yn           ........................................
                                  •  R03 = z1   •  R06 = z2   ..........   •  R3n = zn              •  R3n+f =  vertices of face f

-The vertices of a face are to be coded on 2 digits from the decimal point.
-The integer part represents the 1st vertex, the fractional part represents the other ones.
-For example,  1-2-12-5  (  meaning the polygon  V1V2V12V5 ) must be stored   1.021205

-If the face has more than 5 vertices, it must be divided into several parts:

           1*
             |         *7                          for instance, the heptagon   1-2-3-4-5-6-7  will be stored  1.020304      in a register
     2*    |                                                                                                                       and   1.04050607  in the next one ( or another one )
    3*     |             *6
          4*      5*                            another possibility is for example:   3.04050607  &  3.070102  ... etc ...

Flags: /
Subroutines: /

-Lines 92 & 94 are three-byte  GTOs
 
 

01  LBL "PHV"
02  CLA
03  RCL 00
04  INT
05  3.003
06  *
07  RCL 00          
08  FRC
09  ISG X
10  +
11  STO N
12  LBL 01
13  RCL IND N
14  STO O
15  LBL 02
16  RCL O
17  INT
18  STO O
19  LASTX
20  FRC
21   E2
22  *
23  INT
24  LASTX          
25  FRC
26  ST+ O 
27   E2
28  *
29  INT
30  3
31  ST* Z
32  ST* T 
33  *
34  STO Q 
35  RDN
36  STO P 
37  DSE X
38  DSE Y
39  DSE Y
40  X<>Y
41  RCL IND Y 
42  RCL IND Y
43  *
44  ISG Y
45  CLX
46  DSE Z
47  RCL IND Z
48  RCL IND Z
49  *
50  -
51  RCL IND Q
52  *
53  ST+ M
54  DSE Q          
55  DSE Z
56  CLX
57  RCL IND Z
58  RCL IND P
59  *
60  ISG Y
61  CLX
62  DSE P
63  DSE P
64  RCL IND Y
65  RCL IND P
66  *
67  -
68  RCL IND Q
69  *
70  ST- M
71  ISG P
72  CLX
73  DSE Q          
74  RCL IND Y
75  RCL IND P
76  *
77  ISG P
78  CLX
79  DSE Z
80  RCL IND Z
81  RCL IND P
82  *
83  -
84  RCL IND Q
85  *
86  ST- M
87  RCL O          
88   E2
89  *
90  FRC
91  X#0?
92  GTO 02 
93  ISG N
94  GTO 01 
95  X<> M
96  6
97  /
98  CLA
99  END

 
   ( 164 bytes / SIZE 3n+f+1 )
 
 

      STACK        INPUT       OUTPUT
           X             /        Volume

 
Example:    The polyhedron below has 11 vertices and 12 faces, so      11.012  STO 00

-The coordinates of the vertices are,                                                                       and th 12 faces are

     V1(1,1,10)    store these 3 numbers into  R01 R02 R03                                    f1  1-11-4-3-2    whence   1.11040302   STO 34
     V2(4,1,7)      store these 3 numbers into  R04 R05 R06                                    f2   4-5-9-3         whence   4.050903       STO 35
     V3(7,1,3)      store these 3 numbers into  R07 R08 R09                                    f3   5-6-9            whence    5.0609           STO 36
     V4(8,1,1)      store these 3 numbers into  R10 R11 R12                                    f4   4-11-6-5       whence   4.110605       STO 37
     V5(9,5,1)      store these 3 numbers into  R13 R14 R15                                    f5   6-11-1-8-7   whence    6.11010807   STO 38
     V6(1,10,1)    store these 3 numbers into  R16 R17 R18                                    f6   9-6-7            whence    9.0607           STO 39
     V7(1,8,3)      store these 3 numbers into  R19 R20 R21                                    f7   9-7-10          whence    9.0710           STO 40
     V8(1,5,7)      store these 3 numbers into  R22 R23 R24                                    f8   10-7-8          whence   10.0708          STO 41
     V9(8,5,3)      store these 3 numbers into  R25 R26 R27                                    f9   10-8-2          whence   10.0802          STO 42
    V10(5,4,8)     store these 3 numbers into  R28 R29 R30                                    f10  2-9-10          whence    2.0910           STO 43
    V11(1,1,1)     store these 3 numbers into  R31 R32 R33                                    f11  3-9-2            whence    3.0902           STO 44
                                                                                                                            f12  1-2-8            whence    1.0208           STO 45
  XEQ "PHV"  >>>>   Volume = 197.5   ( in 56 seconds )

-This improbable solid approximately looks like this...
 

 http://hp41programs.yolasite.com/ph.php
 
 

2°) Volume & Area  ( X-Functions Module Required )
 
 

Data Registers:       •  R00 = n.fff = n + f /1000                                 ( These  registers are to be initialized before executing "PHVA" )

                                  •  R11 = x1   •  R14 = x2   ..........   •  R3n+8 = xn          •  R3n+11 =  vertices of face 1
                                  •  R12 = y1   •  R15 = y2   ..........   •  R3n+9 = yn           ........................................
                                  •  R13 = z1   •  R16 = z2   ..........   •  R3n+10 = zn         •  R3n+f+10 =  vertices of face f

                                                 ( R01 thru R09:  temp -  When the program stops, R10 = Volume )
Flags: /
Subroutine:  "D3"  ( cf "Determinants for the HP-41" )

-If you don't want to use synthetic registers  M , N , O ,   replace them by the standard registers R11 , R12 , R13
 replace line 04 by  STO 11, replace line 12 by  14.013 , replace line 37 by  11.001003 and replace lines 99 to 103 by  2  ST/ 11  RCL 11  RCL 10
-Store the coordinates and the vertices into  R14 thru R3n+f+13  ( instead of  R11 thru R3n+f+10 )

-Lines 94 & 96 are three-byte GTOs
 
 

  01  LBL "PHVA"
  02  CLX
  03  STO 10
  04  CLA 
  05  RCL 00 
  06  INT 
  07  3.003 
  08  * 
  09  RCL 00         
  10  FRC
  11  + 
  12  11.01
  13  +
  14  STO N
  15  LBL 01
  16  RCL IND N
  17  STO O
  18  LBL 02
  19  RCL O
  20  INT
  21  STO O
  22  LASTX
  23  FRC
  24   E2
  25  *
  26  INT
  27  LASTX         
  28  FRC
  29  ST+ O         
  30   E2
  31  *
  32  INT
  33  3
  34  ST* Z
  35  ST* T
  36  *
  37  8.001003 
  38  ST+ Z
  39  ST+ T
  40  +
  41  .003
  42  ST+ Z
  43  ST+ X
  44  +
  45  REGMOVE
  46  RDN
  47  REGMOVE
  48  X<>Y
  49  REGMOVE
  50  XEQ "D3"
  51  ST+ 10
  52  RCL 01         
  53  ST- 04
  54  ST- 07
  55  RCL 02
  56  ST- 05
  57  ST- 08
  58  RCL 03
  59  ST- 06
  60  ST- 09
  61  RCL 04
  62  RCL 08
  63  *
  64  RCL 05
  65  RCL 07
  66  *
  67  -
  68  X^2
  69  RCL 04
  70  RCL 09         
  71  *
  72  RCL 06
  73  RCL 07 
  74  *
  75  -
  76  X^2
  77  +
  78  RCL 05 
  79  RCL 09
  80  *
  81  RCL 06
  82  RCL 08
  83  *
  84  -
  85  X^2
  86  +
  87  SQRT
  88  ST+ M
  89  RCL O         
  90   E2
  91  *
  92  FRC
  93  X#0?
  94  GTO 02 
  95  ISG N
  96  GTO 01 
  97  6
  98  ST/ 10
  99  X<> M 
100  2
101  /
102  RCL 10
103  CLA
104  END

 
   ( 168 bytes / SIZE 3n+f+11 )
 
 

      STACK        INPUTS      OUTPUTS
           Y             /          Area
           X             /        Volume

 
Example:       With the same polyhedron,    11.012   STO 00   and store  x1,y1,z1 , .......... into R11 thru R55  ( instead of R01 thru R45 )

    XEQ "PHVA"  >>>>   Volume =  197.5000  =  R10       ( in 76 seconds )
                            X<>Y    Area   =  227.9981
 

3°) Volume & Area of a Polyhedron inscribed in a Sphere
 

-Here, we assume that the polyhedron has a circumsphere and that the edges lengths are known.
-Moreover, all the faces must be convex cyclic polygons and the centers of these circumcircles must be inside the corresponding polygons.
-At last, the center of the circumsphere must be inside the polyhedron.

-Under these assumptions, we follow a method similar to the one used to compute the area of a cyclic polygon:

-The solid angle defined by the center O of the circumsphere ( radius R ), the center O' of the circumcircle of a face ( radius r )
  and the center angle defined by an edge a  may be calculated by:

   OMEGA = 2 Arc tan [ R b / ( R2 - r2 )1/2 ]  -  2 Arc tan b           where  b = [ ( 4 r2 - a2 )1/2 ] / a
 
-The sum of all these solid angles equals 4 PI steradians and we find R by solving this equation.
 

Data Registers:            R00 to R11: temp                  ( All the  "•  Registers" are to be initialized before executing "SPHV" )

                                      •  Rbb1   ....................  •  Ree1    the edges lengths of the face n°1
                                      •  Rbb2   ....................  •  Ree2    the edges lengths of the face n°2
                                          ...............................................................................................

                                      •  RbbN   ....................  •  ReeN    the edges lengths of the face n°N

                                      •  Rbb    ....................  •  Ree    the control numbers  bb1,ee1 ........................  bbN,eeN

   >>>>  When the program stops:

                                          RBB  to  REE = the N radius of the circumcircles of the faces
                                          RBB' to  REE' = the N areas of the faces, in the same order               ( BB' = EE+1 )

Flags: /
Subroutines: /

 "SOLVE"  cf "Linear and Non-Linear Systems for the HP-41" or another root-finding program
 "CPLA"    cf "Area of a Polygon for the HP-41" - paragraph 3°)
 
 

 01  LBL "SPHV"
 02  STO 06
 03  STO 09           
 04  X<>Y
 05  STO 07
 06  STO 08
 07  ENTER^
 08  FRC
 09  ST- Y
 10   E3
 11  *
 12  X<>Y
 13  DSE X
 14  -
 15  +
 16  STO 10
 17  STO 11
 18  LBL 01
 19  RCL IND 08
 20  XEQ "CPLA"
 21  STO IND 10
 22  X<>Y
 23  STO IND 09
 24  SIGN
 25  ST+ 09
 26  ST+ 10
 27  ISG 08
 28  GTO 01
 29  RCL 10           
 30  DSE X
 31   E3
 32  /
 33  ST+ 11
 34  RCL 09
 35  DSE X
 36   E3
 37  /
 38  ST+ 06
 39  RCL 06
 40  0
 41  GTO 04
 42  LBL "U"
 43  STO 04
 44  RCL 06
 45  STO 09
 46  CLX
 47  STO 05
 48  RCL 07
 49  STO 08
 50  LBL 02
 51  RCL IND 08
 52  STO 10
 53  LBL 03
 54  RCL IND 09
 55  ST+ X
 56  X^2
 57  RCL IND 10
 58  X^2
 59  -
 60  SQRT
 61  STO Y
 62  RCL IND 10
 63  R-P
 64  RDN
 65  CHS
 66  X<>Y
 67  RCL 04           
 68  ST* Y
 69  X^2
 70  RCL IND 09
 71  X^2
 72  -
 73  SQRT
 74  RCL IND 10
 75  *
 76  R-P
 77  RDN
 78  +
 79  ST+ 05
 80  ISG 10
 81  GTO 03
 82  ISG 09
 83  CLX
 84  ISG 08
 85  GTO 02
 86  RCL 05
 87  360
 88  -
 89  RTN
 90  LBL 04
 91  RCL IND Y
 92  X>Y?
 93  X<>Y
 94  RDN
 95  ISG Y
 96  GTO 04
 97  "U"
 98  ASTO 00
 99  101
100  %
101  XEQ "SOLVE"
102  CLD
103  CLX
104  STO 02           
105  STO 03
106  RCL 06
107  RCL 11
108  LBL 05
109  RCL 01
110  X^2
111  RCL IND Z
112  X^2
113  -
114  SQRT
115  RCL IND Y
116  ST+ 02
117  *
118  ST+ 03
119  ISG Y
120  RDN
121  ISG Y
122  GTO 05
123  3
124  ST/ 03
125  RCL 01           
126  RCL 02
127  RCL 03
128  END

 
    ( 201 bytes / SIZE ??? )
 
 

      STACK        INPUTS      OUTPUTS
           Z             /             R
           Y       bbb.eee          Area
           X         BBB        Volume

  Where  bbb.eee  is the control number of the list of the edges lengths of each face        bbb > 011
    and       BBB    is an integer such that  RBB to RBB+2N-1 are unused

Example:      The dodecahedron defined below:

-The upper face is a regular pentagon, edges lengths = 1
-The 10 lateral faces are - alternately - a rectangle ( edges 1 , 3 , 1 , 3 ) , a triangle ( edges 3 , 2 , 3 ).  Five times.
-The bottom face is a decagon ( edges 1 , 2 , 1 , 2 , 1 , 2 , 1 , 2 , 1 , 2 )

-Store for instance

   R12 = R13 = R14 = R15 = R16 = 1             ( pentagon )

   R17 = 1   R18 = 3   R19 = 1   R20 = 3         ( rectangle )
   R21 = 1   R22 = 3   R23 = 1   R24 = 3         ( rectangle )
   R25 = 1   R26 = 3   R27 = 1   R28 = 3         ( rectangle )
   R29 = 1   R30 = 3   R31 = 1   R32 = 3         ( rectangle )
   R33 = 1   R34 = 3   R35 = 1   R36 = 3         ( rectangle )

   R37 = 3   R38 = 2   R39 = 3                          ( triangle )
   R40 = 3   R41 = 2   R42 = 3                          ( triangle )
   R43 = 3   R44 = 2   R45 = 3                          ( triangle )
   R46 = 3   R47 = 2   R48 = 3                          ( triangle )
   R49 = 3   R50 = 2   R51 = 3                          ( triangle )

   R52 = 1   R53 = 2   R54 = 1   R55 = 2   R56 = 1   R57 = 2   R58 = 1   R59 = 2   R60 = 1   R61 = 2   ( decagon )

-Then the control numbers:

   R62 = 12.016        R68 = 37.039
   R63 = 17.020        R69 = 40.042
   R64 = 21.024        R70 = 43.045
   R65 = 25.028        R71 = 46.048
   R66 = 29.032        R72 = 49.051
   R67 = 33.036        R73 = 52.061

-So  bbb.eee = 62.073  and we can choose  BBB = 74

    62.073   ENTER^
       74       XEQ "SPHV"   >>>>      V = 20.42904129                         ---Execution time = 25mn12s---
                                           RDN      A = 47.97150815
                                           RDN      R =  2.447576697

-We also get the control number of the radii of the circumcircles in R06 = 74.085

   R74 = 0.850650809  for the pentagon
   R75 = R76 = R77 = R78 = R79 = 1.581138830  for the rectangles ( in fact sqrt(10)/2 )
   R80 = R81 = R82 = R83 = R84 = 1.590990258  for the triangles
   R85 = 2.441244514  for the decagon

-And the control number of the faces areas in R11 = 86.097

   R86 = 1.720477401 = area of the pentagon
   R87 = R88 = R89 = R90 = R91 = 2.999999998  = area of each rectangle = 3 in there were no roundoff-errors
   R92 = R93 = R94 = R95 = R96 = 2.828427127 = area of each triangle = sqrt(8) if there were no roundoff-errors
   R97 = 17.10889510 = area of the decagon.

Notes:

-Since the program is very slow, a good emulator is preferable...
-"SPHV" doesn't work if the center of the circumsphere is outside the polyhedron.
-If all the faces are triangles or cyclic quadrilaterals, line 20 may be replaced by

   SIGN   CLX   LBL 00   RCL IND L   ISG L   GTO 00   XEQ "BRMR"     ( cf "Area of a polygon for the HP-41" )

-The routine would run much faster in this case.