hp41programs

Spheres-Planes

Spheres & Planes for the HP-41


Overview
 

-Given the coordinates of n points in an Euclidean Space of dimension n-1 ( respectively n ),
 "SPHPL" returns one equation of the hypersphere ( respectively hyperplane ) passing through these points:

HyperSphere:    x12 + x22 + .............. + xn-12 + a1 x1 + a2 x2 + ............. + an-1 xn-1 + an = 0
Hyperplane:      xn =  a1 x1 + a2 x2 + ............. + an-1 xn-1 + an
 

>>>  We assume that the hyperplane is not parallel to ( Oxn )
 

Program Listing
 
 

Data Registers:           •  R00 = n                ( Registers R00 thru Rn^2+n are to be initialized before executing "SPHPL" )

                                      •  R01 ........  = all the x1's  , then all the x2's  , ...............

   >>>  When the program stops,     R01 = a1  R02 = a2  .................  Rnn = an

Flag:  F02

  CF 02 = (Hyper) Sphere
  SF 02 = (Hyper) Plane

Subroutine:  "LS3"  ( cf "Linear & Non Linear Systems" )
 
 

 01  LBL "SPHPL"
 02  RCL 00         
 03  X^2
 04  LASTX
 05  FS? 02
 06  CLX
 07  -
 08  1
 09  +
 10   E3
 11  /
 12  RCL 00
 13  +
 14   E3
 15  /
 16  REGMOVE
 17  RCL 00
 18  FS? 02
 19  GTO 04
 20  990
 21  1/X
 22  ISG X
 23  RCL 00         
 24  ST+ Y
 25  *
 26  LBL 01
 27  1
 28  STO IND Y
 29  DSE Y
 30  CLX
 31  LBL 02
 32  RCL IND Y
 33  X^2
 34  -
 35  DSE Y
 36  GTO 02
 37  STO IND Y
 38  CLX
 39  SIGN
 40  -
 41  RCL 00         
 42  X^2
 43  +
 44  DSE Y
 45  GTO 01
 46  XEQ 06
 47  R^
 48  INT
 49  ENTER^
 50  DSE X
 51  0
 52  LBL 03         
 53  RCL IND Y
 54  X^2
 55  +
 56  DSE Y
 57  GTO 03
 58  4
 59  /
 60  RCL IND T
 61  -
 62  SQRT
 63  RTN
 64  LBL 04
 65  X^2
 66  LASTX
 67  ST+ Y
 68  LBL 05
 69  1
 70  X<> IND Z
 71  STO IND Y
 72  DSE Z
 73  RDN
 74  DSE X
 75  GTO 05
 76  LBL 06
 77  RCL 00         
 78  RCL 00
 79  1
 80  +
 81  XEQ "LS3"
 82  END

 
     ( 127 bytes / SIZE n^2+n+1 )
 
 

      STACK        INPUT CF02OUTPUT   SF02OUPUT
           X             /            R          Det

   where  R = radius of the (hyper)sphere and  Det = determinant of the linear system = R00

Example1:   Sphere  CF 02

-Find an equation of the sphere passing through the 4 points:

   A(-1,4,7)
   B(2,4,6)
   C(5,1,0)
   D(3,-3,-4)

-Store these numbers into R01 thru R12 ( in the order: all the x's , all the y's , all the z's )

  -1  STO 01    4  STO 05    7  STO 09
   2  STO 02     4  STO 06   6  STO 10
   5  STO 03     1  STO 07   0  STO 11
   3  STO 04   -3  STO 08  -4  STO 12

-Store n in R00    4  STO 00    CF 02

  XEQ "SPHPL"   >>>>   R = 12.4454 = radius of the sphere                        ---Execution time = 36s---

    and    R01 = -4/3   R02 = 50/3   R03 = -14   R04 = -36

-So the sphere's equation is    x2 + y2 + z2 - 4 x/3 + 50 y/3 - 14 z - 36 = 0

Notes:

-The exact radius is sqrt(1394)/3
-At the end, R00 = the determinant of the linear system = 18 here.
-We assume that the basis is orthonormal.
 

Example2:   Plane  SF 02

-Find an equation of the plane passing through the 3 points:

   A(1,2,-3)
   B(3,4,-1)
   C(2,5,4)

-Store these numbers into R01 thru R09 ( in the order: all the x's , all the y's , all the z's )

   1  STO 01   2  STO 04  -3  STO 07
   3  STO 02   4  STO 05  -1  STO 08
   2  STO 03   5  STO 06   4  STO 09

-Store n in R00    3  STO 00    SF 02

  XEQ "SPHPL"   >>>>   det = 4                                         ---Execution time = 17s---

    and    R01 = -2   R02 = 3   R03 = -7

-So the plane's equation is    z = -2 x + 3 y - 7

Note:

-This program does not work if the plane is // (Oz)
-In this case, swap z with another coordinate.