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


K : First vertex.
L : Second vertex.
M : Third vertex.
T001 LBL T
TOO2 5
T003 STO I
T004 STO(I)
T005 RDN
T006 4
T007 STO I
T008 RDN
T010 STO(I)
T011 RDN
T012 STO M
T013 RDN
T014 STO L
T015 RDN
T016 STO K
T017 R^
T018 X<>Y
T019 -
T020 RDN
T021 RDN
T023 -
T024 X<>Y
T025 RDN
T026 XEQ X001
T027 RCL(I)
T028 ABS
T029 RDN
T030 RCL K
T031 RCL L
T032 RCL M
T033 R^
T034 RTN

Terms of use.

Mnemonic: T for triangle.

If end user need to compute the plane's normalized implicit equation she may simply do XEQ P since X stack register contains a vector normal to the plane and Y register a point in the plane (triangle's third vertex).

Change history:

20071018:1950UTC : This program has been modified as a part of providing for Cartesion to Barycentric coordinate transformation.

No comments: