INTERFACE HLR2; (* Oriented projective geometry in three dimensions. Created 94-05-04 by J. Stolfi. Last edited by stolfi *) IMPORT LR2, LR3, LR3x3; TYPE Point = RECORD c: LR3.T END; (* c[0..2] are coords [w,x,y]. *) Line = RECORD f: LR3.T END; (* f[0..2] are coeffs . *) Sign = [-1..1]; PROCEDURE FromCartesian(READONLY c: LR2.T): Point; (* Point on "hither" half of the plane (i.e, with positive weight) whose Cartesian coordinates are "c". *) PROCEDURE ToCartesian(READONLY p: Point): LR2.T; (* Cartesian coordinates of point "p" (which must be finite). *) PROCEDURE Side(READONLY p: Point; READONLY L: Line): Sign; (* Returns sign of point "p" relative to line "L": 0 on the line, +1 in positive halfplane, -1 in negative halfplane. May give inconsistent results for points very close to the line. *) PROCEDURE Orient(READONLY p, q, r: Point): Sign; (* Returns the orientation (turning sense) of the triangle "p q r". Specifically, the triangle "[1 0 0] [0 1 0] [0 0 1]" has positive orientation. Returns 0 iff the points are collinear. May give inconsistent results for points very close to collinear. *) PROCEDURE Join(READONLY p, q: Point): Line; (* Return the line through "p" and "q". *) PROCEDURE Meet(READONLY K, L: Line): Point; (* Return the point common to "K" and "L". *) PROCEDURE Dir(READONLY frm, tto: Point): LR2.T; (* Direction (a unit-length vector) of point "tto" seen from point "frm". Works even if one of them is at infinity. Does not work if both are at infinity, or coincident, or antipodal. *) PROCEDURE Normal(READONLY L: Line): LR2.T; (* The normal direction of line "L": a unit vector which, on the hither side of the plane, points from "L" into "L"'s positive halfplane. Assumes "L" is not at infinity. *) (* PROJECTIVE MAPS *) TYPE PMap = RECORD dir: LR3x3.T; inv: LR3x3.T END; (* "dir" is the map's matrix, "inv" is its inverse. *) PROCEDURE MapPoint(READONLY p: Point; READONLY m: PMap): Point; (* Applies projective map "m" to point "p". *) PROCEDURE MapLine(READONLY L: Line; READONLY m: PMap): Line; (* Applies projective map "m" to line "L" *) PROCEDURE CompMap(READONLY m, n: PMap): PMap; (* Returns the composition of "m" and "n", applied in that order *) END HLR2.