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]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.

3D case: [[x1, y1, z1], [x0, y0, z0], Z, T | L]-> XEQ L -> No change.

Variables:

Writes:

A : First point defining line.Program:

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.

L001 LBL LComments:

L002 STO B

L003 x<>y

L004 STO A

L005 x<>y

L006 FS? 2

L007 GTO L009

L008 RTN

L009 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 C

L011 RTN

Terms of use.

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.

## No comments:

Post a Comment