File: SVLines2d.mesa
Author: Eric Bier on October 1, 1982 9:02 pm
Last edited by Bier on September 4, 1986 3:32:41 pm PDT
Contents: Routines for finding the intersections of various types of lines and line segments used in the SolidViews package.
DIRECTORY
SV2d;
SVLines2d: CEDAR DEFINITIONS =
BEGIN
LineSeg: TYPE = REF LineSegObj;
LineSegObj: TYPE = SV2d.LineSegObj;
Point2d: TYPE = SV2d.Point2d;
Ray2d: TYPE = REF Ray2dObj;
Ray2dObj: TYPE = SV2d.Ray2dObj;
TrigLine: TYPE = REF TrigLineObj;
TrigLineObj: TYPE = SV2d.TrigLineObj;
TrigLineSeg: TYPE = REF TrigLineSegObj;
TrigLineSegObj: TYPE = SV2d.TrigLineSegObj;
Vector2d: TYPE = SV2d.Vector2d;
TRIGLINES
CreateEmptyTrigLine: PUBLIC PROC RETURNS [line: TrigLine];
CopyTrigLine: PROC [from: TrigLine, to: TrigLine];
Since trig lines are fairly large data structures, you may prefer to allocate one with CreateEmptyTrigLine and repeatedly fill it with new data instead of allocating a new one each time.
FillTrigLineFromPoints: PROC [v1, v2: Point2d, line: TrigLine];
FillTrigLineFromPointAndVector: PROC [pt: Point2d, vec: Vector2d, line: TrigLine];
FillTrigLineFromCoefficients: PROC [sineOfTheta, cosineOfTheta, distance: REAL, line: TrigLine];
FillTrigLineAsNormal: PROC [line: TrigLine, pt: Point2d, normalLine: TrigLine];
This procedures allocate a new TrigLine.
TrigLineFromPoints: PROC [v1, v2: Point2d] RETURNS [line: TrigLine];
TrigLineFromPointAndVector: PROC [pt: Point2d, vec: Vector2d] RETURNS [line: TrigLine];
TrigLineFromCoefficients: PROC [sineOfTheta, cosineOfTheta, distance: REAL] RETURNS [line: TrigLine];
TrigLineNormalToTrigLineThruPoint: PROC [line: TrigLine, pt: Point2d] RETURNS [normalLine: TrigLine];
TrigLineMeetsTrigLine: PROC [line1, line2: TrigLine] RETURNS [intersection: Point2d, parallel: BOOL];
TrigLineMeetsYAxis: PROC [line: TrigLine] RETURNS [yInt: REAL, parallel: BOOL];
TrigLineMeetsTrigLineSeg: PROC [line: TrigLine, seg: TrigLineSeg] RETURNS [intersection: Point2d, noHit: BOOL];
TrigLineDistance: PROC [pt: Point2d, line: TrigLine] RETURNS [d: REAL];
PointProjectedOntoTrigLine: PROC [pt: Point2d, line: TrigLine] RETURNS [projectedPt: Point2d];
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 FillTrigLineAsNormal above.
TRIGLINESEGS
CreateTrigLineSeg: PROC [v1, v2: Point2d] RETURNS [seg: TrigLineSeg];
CreateEmptyTrigLineSeg: PROC RETURNS [seg: TrigLineSeg];
FillTrigLineSeg: PROC [v1, v2: Point2d, seg: TrigLineSeg];
CopyTrigLineSeg: PROC [from: TrigLineSeg, to: TrigLineSeg];
TrigLinePointOnTrigLineSeg: PROC [pt: Point2d, seg: TrigLineSeg] RETURNS [BOOL];
Assumes pt is on seg.line. Is it on seg?
NearestEndpoint: PROC [pt: Point2d, seg: TrigLineSeg] RETURNS [endpoint: Point2d];
DistanceSquaredToNearestEndpoint: PUBLIC PROC [pt: Point2d, seg: TrigLineSeg] RETURNS [distanceSquared: REAL];
Faster than DistancePointToPoint[pt, NearestEndpoint[pt, seg]] (if you don't care what the endpoint is).
DistancePointToTrigLineSeg: PROC [pt: Point2d, seg: TrigLineSeg] RETURNS [distance: REAL];
Perpendicular distance if possible, else distance to nearest endpoint.
DistanceSquaredPointToTrigLineSeg: PROC [pt: Point2d, seg: TrigLineSeg] RETURNS [distanceSquared: REAL];
POINT2DS
DistancePointToPoint: PROC [p1, p2: Point2d] RETURNS [distance: REAL];
DistanceSquaredPointToPoint: PROC [p1, p2: Point2d] RETURNS [distance: REAL];
PointLeftOfTrigLine: PROC [distance: REAL, pOnLine: Point2d, line: TrigLine] RETURNS [point: Point2d];
point is a point to the left of the directed line, on the normal to the line which intersects the line at pOnLine. If distance is negative, the point will be to the right of the directed line.
LINESEGS
CreateLineSeg: PROC [v1, v2: Point2d] RETURNS [seg: LineSeg];
RAYS
CreateRay: PROC [basePoint: Point2d, direction: Vector2d] RETURNS [ray: Ray2d];
CreateRayFromPoints: PROC [p1, p2: Point2d] RETURNS [ray: Ray2d];
RightHorizontalRay: PROC [point: Point2d] RETURNS [horizRayThruPoint: Ray2d];
UpVerticalRay: PROC [point: Point2d] RETURNS [vertRayThruPoint: Ray2d];
RayMeetsBox: PROC [ray: Ray2d, xmin, ymin, xmax, ymax: REAL] RETURNS [count: NAT, params: ARRAY[1..2] OF REAL];
Find intersections of the directed half-line only.
LineRayMeetsBox: PROC [ray: Ray2d, xmin, ymin, xmax, ymax: REAL] RETURNS [count: NAT, params: ARRAY[1..2] OF REAL];
Ignore the direction of the ray. Find all of the line intersections.
EvalRay: PROC [ray: Ray2d, param: REAL] RETURNS [point: Point2d];
END.