GGLines.mesa
Author: Eric Bier on June 4, 1985 4:58:33 pm PDT
Last edited by Bier on January 5, 1987 7:52:21 pm PST
Contents: Routines for finding the intersections of various types of lines and line segments
Pier, December 6, 1985 10:01:40 am PST
DIRECTORY
GGBasicTypes, ImagerTransformation;
GGLines: CEDAR DEFINITIONS =
BEGIN
Point: TYPE = GGBasicTypes.Point;
Edge: TYPE = GGBasicTypes.Edge;
Line: TYPE = GGBasicTypes.Line;
Ray: TYPE = GGBasicTypes.Ray;
Vector: TYPE = GGBasicTypes.Vector;
Lines
CreateEmptyLine: PROC RETURNS [line: Line];
CopyLine: PROC [from: Line, to: Line];
Since lines are fairly large data structures, you may prefer to allocate one with CreateEmptyLine and repeatedly fill it with new data instead of allocating a new one each time.
FillLineFromPoints: PROC [v1, v2: Point, line: Line];
FillLineFromPointAndVector: PROC [pt: Point, vec: Vector, line: Line];
FillLineFromCoefficients: PROC [sineOfTheta, cosineOfTheta, distance: REAL, line: Line];
FillLineFromPointAndAngle: PROC [pt: Point, degrees: REAL, line: Line];
FillLineNormalToLineThruPoint: PROC [line: Line, pt: Point, normalLine: Line];
FillLineLeftOfLine: PROC [line: Line, dist: REAL, parallelLine: Line];
FillLineRightOfLine: PROC [line: Line, dist: REAL, parallelLine: Line];
FillLineTransform: PROC [fixed: Line, transform: ImagerTransformation.Transformation, line: Line];
transform is applied to fixed. The resulting transformed line is stored in line. It is OK if fixed and line are the same.
These procedures allocate a new Line.
LineFromPoints: PROC [v1, v2: Point] RETURNS [line: Line];
LineFromPointAndVector: PROC [pt: Point, vec: Vector] RETURNS [line: Line];
LineFromCoefficients: PROC [sineOfTheta, cosineOfTheta, distance: REAL] RETURNS [line: Line];
LineFromPointAndAngle: PROC [pt: Point, degrees: REAL] RETURNS [line: Line];
LineNormalToLineThruPoint: PROC [line: Line, pt: Point] RETURNS [normalLine: Line];
LineLeftOfLine: PROC [line: Line, dist: REAL] RETURNS [parallelLine: Line];
LineRightOfLine: PROC [line: Line, dist: REAL] RETURNS [parallelLine: Line];
LineTransform: PROC [fixed: Line, transform: ImagerTransformation.Transformation] RETURNS [transformedLine: Line];
Makes a new line that results by transforming fixed by transform.
Computations on Lines
LineMeetsLine: PROC [line1, line2: Line] RETURNS [intersection: Point, parallel: BOOL];
LineMeetsYAxis: PROC [line: Line] RETURNS [yInt: REAL, parallel: BOOL];
LineMeetsEdge: PROC [line: Line, edge: Edge] RETURNS [intersection: Point, noHit: BOOL];
EdgeMeetsEdge: PROC [e1, e2: Edge] RETURNS [intersection: Point, noHit: BOOL];
SignedLineDistance: PROC [pt: Point, line: Line] RETURNS [d: REAL];
LineDistance: PROC [pt: Point, line: Line] RETURNS [d: REAL];
PointProjectedOntoLine: PROC [pt: Point, line: Line] RETURNS [projectedPt: Point];
We drop a normal from the point onto the line and find where it hits
the line equation of the normal we drop can be found as in FillLineAsNormal above.
PointOnLine: PROC [line: Line] RETURNS [pt: Point];
Finds any old point on line and returns it.
DirectionOfLine: PROC [line: Line] RETURNS [direction: Vector];
Returns the direction vector of line.
Edges
CreateEmptyEdge: PROC RETURNS [edge: Edge];
CopyEdge: PROC [from: Edge, to: Edge];
Since Edges are fairly large data structures, you may prefer to allocate one with CreateEmptyEdge and repeatedly fill it with new data instead of allocating a new one each time.
FillEdge: PROC [v1, v2: Point, edge: Edge];
FillEdgeTransform: PROC [fixed: Edge, transform: ImagerTransformation.Transformation, edge: Edge];
CreateEdge: PROC [v1, v2: Point] RETURNS [edge: Edge];
EdgeTransform: PROC [fixed: Edge, transform: ImagerTransformation.Transformation] RETURNS [edge: Edge];
These procedures allocate a new edge.
Computations on Edges
LinePointOnEdge: PROC [pt: Point, edge: Edge] RETURNS [BOOL];
Assumes pt is on edge.line. Is it on edge?
NearestEndpoint: PROC [pt: Point, edge: Edge] RETURNS [endpoint: Point];
DistanceSquaredToNearestEndpoint: PUBLIC PROC [pt: Point, edge: Edge] RETURNS [distanceSquared: REAL];
NearestPointOnEdge: PROC [pt: Point, edge: Edge] RETURNS [onEdge: Point];
The nearest point on edge.line to pt, if the nearest point is on edge. Otherwise, the nearest endpoint.
DistancePointToEdge: PROC [pt: Point, edge: Edge] RETURNS [distance: REAL];
Distance[pt, NearestPointOnEdge[pt, edge]].
DistanceSquaredPointToEdge: PROC [pt: Point, edge: Edge] RETURNS [distanceSquared: REAL];
OnEdge: PROC [pt: Point, edge: Edge] RETURNS [BOOL];
Returns TRUE if pt is at a very small distance from edge.
Points
DistancePointToPoint: PROC [p1, p2: Point] RETURNS [distance: REAL];
DistanceSquaredPointToPoint: PROC [p1, p2: Point] RETURNS [distance: REAL];
PointLeftOfLine: PROC [distance: REAL, pOnLine: Point, line: Line] RETURNS [point: Point];
RAYS -- Used by GGShapes to draw infinite lines (e.g. to do manual clipping)
CreateRay: PROC [basePoint: Point, direction: Vector] RETURNS [ray: Ray];
CreateRayFromPoints: PROC [p1, p2: Point] RETURNS [ray: Ray];
LineRayMeetsBox: PROC [ray: Ray, xmin, ymin, xmax, ymax: REAL] RETURNS [count: NAT, params: ARRAY[1..2] OF REAL];
EvalRay: PROC [ray: Ray, param: REAL] RETURNS [point: Point];
END.