INTERFACE R3; (* Linear algebra in R^3. Created 93-04-18 by Marcos C. Carrard. Based on R3.pas by J. Stolfi. Last edited by stolfi *) IMPORT Wr; TYPE T = ARRAY [0..2] OF REAL; CONST N = 3; Zero = T{0.0, ..}; Ones = T{1.0, ..}; Axis = ARRAY [0..2] OF T{ T{1.0, 0.0, 0.0}, T{0.0, 1.0, 0.0}, T{0.0, 0.0, 1.0} }; PROCEDURE Add(READONLY a, b: T): T; (* Returns "a + b". *) PROCEDURE Sub(READONLY a, b: T): T; (* Returns "a - b". *) PROCEDURE Neg(READONLY a: T): T; (* Returns "-a" *) PROCEDURE Scale(s: LONGREAL; READONLY a: T): T; (* Returns "s * a"; *) PROCEDURE Weigh(READONLY a, b: T): T; (* Returns "a" times "b" componentwise. *) PROCEDURE Mix(s: LONGREAL; READONLY a: T; t: LONGREAL; READONLY b: T): T; (* Returns "s * a + t * b". *) PROCEDURE Length(READONLY a: T): LONGREAL; (* Returns the Euclidean norm (length) of vector "a". *) PROCEDURE LInfLength(READONLY a: T): REAL; (* Returns the L_infinity norm of vector "a", i.e. the max absolute coordinate. *) PROCEDURE LengthSqr(READONLY a: T): LONGREAL; (* Returns the square of the Euclidean length of vector "a", i.e. Dot(a,a). *) PROCEDURE Dist(READONLY a, b: T): LONGREAL; (* Returns the Euclidean distance between points "a" and "b". *) PROCEDURE DistSqr(READONLY a, b: T): LONGREAL; (* Returns the square of the Euclidean distance between points "a" and "b". *) PROCEDURE LInfDist(READONLY a, b: T): REAL; (* Returns the max absolute difference between the coordinates of "a" and "b". *) PROCEDURE Dir(READONLY a: T): T; (* Returns the vector "a" scaled to unit Euclidean *) PROCEDURE LInfDir(READONLY a: T): T; (* Returns the vector "a" scaled to unit L_infinity norm *) PROCEDURE Dot(READONLY a, b: T): LONGREAL; (* Returns the dot product of vectors "a" and "b" *) PROCEDURE Det(READONLY a, b, c: T): LONGREAL; (* Returns the determinant of the matrix whose rows are "a", "b", and "c". *) PROCEDURE Cross(READONLY a, b: T): T; (* Returns the cross-product of "a" by "b": a vector such that "Dot(Cross(a, b), c) = Det(a, b, c)" for all "c". *) PROCEDURE Project(READONLY a, u: T): T; (* Returns the component of vector "a" that is parallel to "u". *) PROCEDURE Orthize(READONLY a, u: T): T; (* Returns the component of vector "a" that is orthogonal to "u". *) PROCEDURE Print(wr: Wr.T; READONLY a: T); (* Prints "a" to the given writer. *) END R3.