Wednesday, September 26, 2007

HP-35s Euclid Implementation - VII : Defining a plane

Time to start working with the plane: First a data entry program to define a plane given a point in the plane and a vector normal to it.

This program is similar to the L program in that it computes a hyperplane's (now of 3D space) implicit equation (problem 9A of the specification).

The program accepts the defining point in the Y stack register and a vector normal to the plane in X stack register.

It stores the point that defines the plane in variable P (mnemonic: plane's point), the normalized normal vector in variable N (mnemonic: plane's normal) and the constant d of the plane's implicit equation ax+by+cz+d=0 in variable O (mnemonic: distance from origo to plane, true since equation normailized; see comments section). Since [a, b, c] is the plane's normal (stored in variable N) the computation of d=-(N*P) (* is here the dot product) is what is to be done to compute the plane's implicit equation.

Stack Input/Output:
[[nx, ny, nz], [x, y, z], Z, T | L]-> XEQ P->[d, [a, b, c], [x, y, z], Z | [nx, ny, nz]]
Where [nx, ny, nz] is a vector normal to the plane and (x, y, z) is a point in the plane. Output is the constants of the normalized implicit plane equation ax+by+cz+d=0. Content of Y stack register [a, b, c] is [nx, ny, nz] normalized, orginal vector can be found in LASTX register.


N : Plane's normalized normal vector.
O : Signed distance to origo (0, 0, 0).
P : Defining point in plane.
P002 XEQ X004
P003 STO N
P004 X<>Y
P005 STO P
P006 eq -(PxN)
P007 STO O
P008 RDN
P009 X<>Y
P010 R^
P011 RTN

Terms of use.

Mnemonics: P for Plane.

Importent to remember when entering line P006: Stroke the +/- key not the - operation key to get the equation's sign. Using the - operator key will result in a program that looks fine but causes a SYNTAX error when line P006 is executed.

Reason for normalizing the normal vector defining the plane are:
  • Because it is often done. For example planes defined by a triangles found in the dataset of a Computer Graphics application's polygon model typical has normalized normal vectors associated with it's triangles.
  • When the normal vector defining the plane is normalized the plane's implicit equation is said to be normalized. Representing the plane using the normalized implicit equation has the advantage that some formulas for plane problems becomes simplified.
Since the implicit equation is normalized the d term of ax+by+cd+d, the value in the X stack register is the signed distance from the origo (0, 0, 0) to the plane.

No comments: