## Sunday, September 30, 2007

### HP-35s Euclid Implementation - VIII : Defining a triangle

Yet another 'data entry' program, this one for defining a triangle in 3D space. It will be needed for solving triangle problems (14-17 of the requirements) but is also usefull to solve plane problems when the plane is defined by three points (problem 9 A of the requirements), so introducing it now.

The program accepts triangle's first point in the Z stack register, second point in Y stack register and third point in the X stack register, all expected to be 3D vectors. Program performs two tasks:
1. Store the points in the variables K (first point), L (second point) and M (third point). These variables will be used later in solving triangle problems.
2. Returns in the X stack register a vector normal to the plane defined by the triangle computed as (L-K)x(M-K) (x is here the cross product). This gives the area of the triangle since the length of this vector is twice the area (keystrokes: ABS, 2, /).
Stack Input/Output:
`[[x2, y2, z2], [x1, y1, z1], [x0, y0, z0] | L]->XEQ T->[[nx, ny, nz], [x2, y2, z2], [x1, y1, z1], [x0, y0, z0] | L]`
Where v0=(x0, y0, z0) is first, v1=(x1, y1, z1) is second, v2=(x2, y2, z2) is the third triangle vertex and [nx, ny, nz] is the cross product (v1-v0)x(v2-v0).

Variables:

Writes:
`K : First vertex.L : Second vertex.M : Third vertex.`
Program:
`T001 LBL TTOO2 5T003 STO IT004 STO(I)T005 RDNT006 4T007 STO IT008 RDNT009 LASTXT010 STO(I)T011 RDNT012 STO MT013 RDNT014 STO LT015 RDNT016 STO KT017 R^T018 X<>YT019 -T020 RDNT021 RDNT022 LASTXT023 -T024 X<>YT025 RDNT026 XEQ X001T027 RCL(I)T028 ABST029 RDNT030 RCL KT031 RCL LT032 RCL MT033 R^T034 RTN`