Monday, October 1, 2007

HP-35s Euclid Implementation - IX : Signed distance from a plane to a point

The plane is the hyperplane of 3D (like a line in 2D divides the space a plane divide 3D space) so since program P stores the plane's normalized implicit equation point p=(x, y, z)'s signed distance to the plane is ax+by+cz+d or (since [a, b, c] is stored in variable N and d is stored in variable O) N*p+O where * here is the dot product operator.

I choose to modify the S program so that it computes the signed distance in 2D (as before) if flag 2 is set and else computes signed distance in 3D (to the plane defined by the P program); problem 10 of the requirements.

Stack Input/Output:

2D case:
[[x, y], Y, Z, T | L]-> XEQ S ->[d, Y, Z, T | [x, y]]
3D case:
[[x, y, z], Y, Z, T | L]-> XEQ S ->[d, Y, Z, T | [x, y, z]]
Where (x, y) or (x, y, z) is point to find distance to and d is the signed distance.

Variables:

Reads:
C : [a, b, c], constants of line's normalized implicit equation. Populated by the L program. Reads in 2D case (flag 2 set).
N : Plane's normalized normal vector. Populated by the P program. Reads in 3D case.
O : Plane's distance to origo (0, 0, 0). Populated by the P program. Reads in 3D case.
Program:
S001 LBL S
S002 ABS
S003 RDN
S004 FS? 2
S005 GTO 008
S006 eq LASTXxN+O
S007 RTN
S008 eq (([1,0,0]xC)x([1, 0]xLASTX))+(([0,1,0]xC)x([0,1]xLASTX))+[0,0,1]xC
S009 RTN
Comments:

Terms of use.

As before point to find signed distance to in the X stack register: Again, if had an dim operator for vectors would not need for the end user to toggle the 2 flag, could branch on dimension of argument in the X stack register.

No comments: