JunoMatrix.mesa
Last Edited by: Stolfi, June 12, 1984 5:45:51 pm PDT

Tools for coordinate transformations and matrix algebra.

DIRECTORY

JunoStorage USING [Coords, Point, Frame];

JunoMatrix: DEFINITIONS =

BEGIN OPEN Stor: JunoStorage;

Point: TYPE = Stor.Point;

Coords: TYPE = Stor.Coords;

Matrix: TYPE = ARRAY [1..3] OF ARRAY [1..3] OF REAL;

Frame: TYPE = Stor.Frame;

Identity: PROC [m: REF Matrix ← NIL] RETURNS [mid: REF Matrix];
Returns an identity matrix.
The matrix m is optional, and used to store the result if given (saves alloc.)

GetFrameMatrix
: PROC [frame: Frame, m: REF Matrix ← NIL] RETURNS [mr: REF Matrix];
Returns the coordinate transform matrix for the frame determined by the points org, xP, yP (the last one or two may be NIL).
The resulting matrix satisfies m*[0,0,1]^T= org, m*[1,0,1]^T= hor, m*[1,0,1]^T= ver.
The matrix m is optional, and used to store the result if given (saves alloc.)

InvertMatrix
: PROC [m: REF Matrix, work: REF Matrix ← NIL]
RETURNS [mInv: REF Matrix, singular: BOOL];
Inverts m^ into mInv^ by pivoting three times; or sets "singular" flag.
The matrix work is optional, and used to store the result if given (saves alloc.)

MultiplyMatrix
: PUBLIC PROC [ma, mb: REF Matrix, mc: REF Matrix ← NIL]
RETURNS [mr: REF Matrix];
Multiply ma^ * mb^.
The matrix mc is optional, and used to store the result if given (saves alloc.)

ComputeTransform
: PROC
[src, dest: Frame, mm: REF Matrix ← NIL]
RETURNS [mat: REF Matrix, singular: BOOL];
Computes the transform matrix that maps src to dest column vectors with third component 1.
Hence we compute the inverse of src and multipy on the left by dest.
The matrix mm is optional, and used to store the result if given (saves alloc.)

MapCoords: PROC [coords: Coords, mat: REF Matrix] RETURNS [cMap: Coords];
Transforms coords by the given matrix

END.