Post Reply 
Hp 50g Math question: Intersection of 2 triangulars
12-25-2013, 01:10 PM
Post: #12
RE: Math question: Intersection of 2 triangulars
Hello all,

The great program for solving this problem isn't ready. But the frame programe is ready and some sub programs which I want to present.
Some remarks: I use the decimal comma and not a point and the command \->NUM can be deleted if it is shure that all values are reals (otherwise the if conditions will not work correct). The programs are all "hard coded", I don't use the solve abilities of the HP 50g in hope that my solutions are faster and I can format the output in a way I want. If your are interested in the mathematics behind these programs, let me know.

The first one: "NONUL":

Its function is to find a non-zero value in a 3-dim vector.

Input: stack 1: a vector
Output: stack 2: value
stack 1: index

This program is used in program "CUTLL" avoiding a possible division by zero..

Code:

%%HP: T(3)A(R)F(,);
\<< OBJ\-> DROP DUP
  IF 0, \=/
       THEN 3,
       ELSE UNROT DUP
              IF 0, \=/
                       THEN 2,
            ELSE UNROT DUP
                  IF 0, \=/
                       THEN 1,
                       ELSE 0,
                       END
            END
       END 4 ROLLD 4 ROLLD DROP2
\>>
If the vector is the null-vector index is zero (and the value, too).

The second is called: "CUTPL"

Its function is to find a interection between a line and a plane.

Input: stack 4: position vector of the line
stack 3: direction vector of the line
stack 2: position vector of the plane
stack 1: normal vector of the plane
Output: stack 1: { } if there is no intersection
stack 1: { [position vector] [direction vector] } if the
line lies in the plane
stack 1: single value (if that value is inserted in the line equation
you get the position vector of the intersecting point.)
Because this value is importent later on, this program stops
here with the calculation.
Code:

%%HP: T(3)A(R)F(,);
\<< \-> TG R TE N
  \<< TG TE - N DOT NEG R N DOT DUP \->NUM
    IF 0, ==
         THEN SWAP \->NUM
                 IF 0, ==
              THEN TG R 2, \->LIST
              ELSE { }  END 
           SWAP DROP
         ELSE /  END
  \>>
\>>

The third one is "CUTLL".

Its function is to find a interection between a line and a line.

Input: stack 4: position vector of the line 1
stack 3: direction vector of the line 1
stack 2: position vector of the line 2
stack 1: direction vector of the line 2
Output: stack 1: { } if there is no intersection
stack 1: { [position vector 1] [direction vector 1] } if the
lines are identical
stack 1: single value (if that value is inserted in the line equation
of line 1 you get the position vector of the intersecting point.)
Because this value is importent later on, this program stops
here with the calculation.

Code:

%%HP: T(3)A(R)F(,);
\<< \-> T1 R1 T2 R2
  \<< T2 T1 - R2 NEG CROSS 
         DUP R1 R2 NEG CROSS 
         DUPDUP ABS \->NUM
    IF 0, ==
    THEN ROT ABS \->NUM
             IF 0, ==
             THEN 3, DROPN T1 R1 2, \->LIST
             ELSE 3, DROPN { } END
    ELSE ROT CROSS ABS \->NUM
             IF 0, \=/
             THEN DROP2 { }
             ELSE NONUL ROT SWAP GET SWAP / END
    END
  \>>
\>>

Sincerely peacecalc
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Math question: Intersection of 2 triangulars - peacecalc - 12-25-2013 01:10 PM



User(s) browsing this thread: 1 Guest(s)