Tuesday, September 25, 2007

Cross product and normalizing a vector on the HP-35s

NOTE: An error has been corrected in this program listing around 20070927 16:30 UTC.

Now need to calculate the cross product of two 3D vector in the HP-35s Euclid Pack implementation. One should think that the cross product would have been a build in function on th 35s, but no, we need to roll our own: Line 001-003 in the following program.

Normalizing a vector (keeping direction but making it of unit length) is a common operation performed on directional only vectors. Subroutine X006 performs normalization.

Stack Input/Output:

Cross product:
[[ux, uy, uz], [vx, vy, vz], Z, T | L]-> XEQ X001 ->[[wx, wy, wz], [ux, uy, uz], [vx, vy, vz], Z | L]
Where the w vector is the result of u*v.

Normalization:
[u, Y, Z, T | L]-> XEQ U004 ->[u/|u|, Y, Z, T | u]
Where u is a 2D or 3D.

Program:
X001 LBL X
X002 eq [([0,1,0]xREGY)x([0,0,1]xREGX)-([0,0,1]xREGY)x([0,1,0]xREGX),
([0,0,1]xREGY)x([1,0,0]xREGX)-([1,0,0]xREGY)x([0,0,1]xREGX),
([1,0,0]xREGY)x([0,1,0]xREGX)-([0,1,0]xREGY)x([1,0,0]xREGX)]
X003 RTN
X004 ABS
X005 RDN
X006 eq LASTX/REGT
X007 RTN
Comments:

Terms of use.

No comments: