GGLines.mesa
Author: Eric Bier on June 4, 1985 4:58:33 pm PDT
Last edited by Bier on October 1, 1985 5:31:09 pm PDT
Contents: Routines for finding the intersections of various types of lines and line segments
GGLines: CEDAR DEFINITIONS =
BEGIN
Point: TYPE = GGModelTypes.Point;
Edge: TYPE = GGModelTypes.Edge;
Line: TYPE = GGModelTypes.Line;
Ray: TYPE = GGModelTypes.Ray;
Vector:
TYPE = GGModelTypes.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];
FillLineAsNormal: PROC [line: Line, pt: Point, normalLine: Line];
FillLineLeftOfLine: PROC [line: Line, dist: REAL, parallelLine: Line];
FillLineRightOfLine: PROC [line: Line, dist: REAL, parallelLine: Line];
This 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];
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];
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.
CreateEdge: PROC [v1, v2: Point] RETURNS [edge: Edge];
CreateEmptyEdge: PROC RETURNS [edge: Edge];
FillEdge: PROC [v1, v2: Point, edge: Edge];
CopyEdge: PROC [from: Edge, to: Edge];
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];
Faster than DistancePointToPoint[pt, NearestEndpoint[pt, edge]] (if you don't care what the endpoint is).
DistancePointToEdge:
PROC [pt: Point, edge: Edge]
RETURNS [distance:
REAL];
Perpendicular distance if possible, else distance to nearest endpoint.
DistanceSquaredPointToEdge: PROC [pt: Point, edge: Edge] RETURNS [distanceSquared: REAL];
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.