INTERFACE R2x2; (* Operations on 2x2 matrices: linear maps of R^2. Created 94-05-04 by J. Stolfi. Last edited by stolfi *) IMPORT R2, Wr; TYPE T = ARRAY [0..1], [0..1] OF REAL; CONST N = 2; Null = T{R2.Zero, ..}; Identity = T{ R2.T{1.0, 0.0}, R2.T{0.0, 1.0} }; PROCEDURE MapRow(READONLY a: R2.T; READONLY m: T): R2.T; (* Returns the product of row vector "a" by the matrix "m". *) PROCEDURE MapCol(READONLY m: T; READONLY a: R2.T): R2.T; (* Returns the product of matrix "m" by the column vector "a". *) PROCEDURE Mul(READONLY m, n: T): T; (* Returns the product of matrices "m" and "n", in that order. *) PROCEDURE Det(READONLY m: T): LONGREAL; (* Returns the determinant of matrix "m". *) PROCEDURE Inv(READONLY m: T): T; (* Returns the inverse of matrix "m". Assumes its determinant is non-zero. *) PROCEDURE Adj(READONLY m: T): T; (* Returns the adjoint of matrix "m", such that "m * result = I * Det(m)" *) PROCEDURE Rotation(angle: LONGREAL; scale: LONGREAL := 1.0d0): T; (* Returns an orthogonal matrix "R" such that "RowMul(v, R)" is "v" rotated by "angle" radians counterclockwise around the origin, and magnified by "scale". Thus, for exemple, "Rotation(Pi/2)" will take "(0,1)" to "(1,0)". *) PROCEDURE Print(wr: Wr.T; READONLY m: T; indent: CARDINAL := 0); (* Prints the matrix to the given writer. Indents continuation lines by at least "indent" blanks. *) END R2x2.