## 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:

`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. `
`S001 LBL SS002 ABSS003 RDNS004 FS? 2S005 GTO 008S006 eq LASTXxN+OS007 RTNS008 eq (([1,0,0]xC)x([1, 0]xLASTX))+(([0,1,0]xC)x([0,1]xLASTX))+[0,0,1]xCS009 RTN`