Friday, September 21, 2007

HP-35s Euclid Implementation - II : Signed distance from a 2D line to a 2D point

NOTE: This program has been modified.

The 2D line is the hyperplane of 2D space meaning a line divide the space (a point is the hyperplane of 1D space and plane the is the hyperplane of 3D space). This manifest itself in that if we use the left side of the implicit equation ax+by+c=0 as a function we get out a number that is 0 if (x, y) is on the line, negative sign if on one side and positive sign if on the other.

In the case that |[a, b]|=1, the implicit equation is said to be normalized and ax+by+c is in fact the (signed) distance from the point (x, y) to the line. Since the program L do store the normalized line equation this program simply computes ax+by+c.

Stack Input/Output:
[[x, y], Y, Z, T | L]-> XEQ S ->[d, Y, Z, T | [x, y]]
Where (x, y) 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.
Program:
S001 LBL S
S002 ABS
S003 RDN
S004 eq (([1,0,0]xC)x([1, 0]xLASTX))+(([0,1,0]xC)x([0,1]xLASTX))+[0,0,1]xC
S005 RTN
Comments:

Terms of use.

Mnemonic: S for signed distance.

The line distance is computed from is entered using the program L and the point is in the X stack register as a 2D vector.

This program does not test for the 2 flag since it only work on a 2D problem.

An important feature I wanted from this program is that it behaves like a build in function: The argument in the X stack register (the point) goes to LASTX register, result (signed distance) appears in the X stack register and Y, Z and T stack registers are left unchanged. First version fooled around saving stack content in indirect registers, but then I found Valentin Albillo (VA) trick in a MoHPC forum post used here: Thanks VA, expects that to be utilized more!

Change history:

20071001:2010UTC : No longer divide ax+by+c by |[a, b]| since now the normalized implicit equation is stored.
20071001:2210UTC : New version of program.

No comments: