## Friday, September 21, 2007

### HP-35s Euclid Implementation - I : Defining a line

The first program in the HP-35s Euclid Pack implementation is one to accept a line defined by two points to be used for further calculations. The program stores first point in variable A and second point in variable B.

What I realy would like is if this program could tell the dimension of vectors or if input is scalar, this could be used for:

1. Check if gets what is expected (vectors). As it is now the program will do nothing more for 3D lines but to store points in correct variables, might as well use STO commands directly in 3D case.

2. For 2D lines I would like it to compute the constants of the lines implicit equation ax+by+c=0 and store it in variable C as a 3D vector [a, b, c] (problem 1 in the specification). Since this is not possible I am introducing a 2D mode: If flag 2 is set then user is working in 2D, programs that need do perform different based on dimension of input will check this flag.

Stack Input/Output:
`2D case: [[x1, y1], [x0, y0], Z, T | L]-> XEQ L ->[[a, b, c], [x1, y1], [x0, y0], Z | L]3D case: [[x1, y1, z1], [x0, y0, z0], Z, T | L]-> XEQ L -> No change.`
Where x0, y0, z0 are coordinates for first point defining the line, x1, y1, z1 are coordinates for second point defining the line and in the 2D case a, b, and c are the constants of line's implicit equation ax+by+c.

Variables:

Writes:
`A : First point defining line.B : Second point defining the line.C : [a, b, c] the constants of 2D line's normalized implicit equation ax+by+c. Not populated if input is a 3D line.`
Program:
`L001 LBL LL002 STO BL003 x<>yL004 STO AL005 x<>yL006 FS? 2L007 GTO L009L008 RTNL009 eq [[0,1]xA+[0,-1]xB,         [1,0]xB+[-1,0]xA,         ([1,0]xA)x([0,1]xB)-([1,0]xB)x[0,1]xA)]/(ABS(B-A))L010 STO CL011 RTN`

Mnemonic: L for line.

The implicit equation (2D case) stored is normalized since the vector [a, b] is made to be of length 1, which means that for a point x, y not on the line ax+by+c is the signed distance to the line (two 2D points has opposite distance sign if not on same side of the 2D line). The program S computes the signed distance. One piece of information one get right away is the line's distance to origo (0, 0): |c|.

I realy like that one can use equations in programs.

All those vectors with signed 1s and 0s elements are mask vectors to get out a vector's components needed since no operation to do so is provided. I knew about that trick long before getting my hands on machine reading MoHPC forum posts...

I actual did ask about the runtime type problem at MoHPC in this thread, if there was a solution I'am sure Katie would have found it...

For all its shortcomings I still find the vector type very usefull because it lets us store vectors of 2D and 3D space in a single register. Sure I got 800 registers, but this type of data I would like to use the A-H, K-Z variable registers for easy access: Without the vector type I would have used 9 variables not 3, also the stack would not been high enough for non prompt input.

Change history:

20071001:2010UTC : Changed to store normalized implicit equation.