GGCircles.mesa
Author: Eric Bier on June 4, 1985 4:58:33 pm PDT
Last edited by Bier on January 5, 1987 7:57:14 pm PST
Contents: Routines for finding the intersections of various types of circles, lines, and points.
Pier, December 6, 1985 10:01:18 am PST
GGCircles: CEDAR DEFINITIONS =
BEGIN
Arc: TYPE = GGBasicTypes.Arc;
Circle: TYPE = GGBasicTypes.Circle;
Point: TYPE = GGBasicTypes.Point;
Edge: TYPE = GGBasicTypes.Edge;
Line: TYPE = GGBasicTypes.Line;
Vector:
TYPE = GGBasicTypes.Vector;
Circles
CreateEmptyCircle: PROC [] RETURNS [circle: Circle];
CopyCircle: PROC [from: Circle, to: Circle];
Since circles are fairly large data structures, you may prefer to allocate one with CreateEmptyCircle and repeatedly fill it with new data instead of allocating a new one each time.
FillCircleFromPointAndRadius:
PROC [pt: Point, radius:
REAL, circle: Circle];
"circle" now has center at "pt" and radius of "radius".
CircleFromPointAndRadius:
PROC [pt: Point, radius:
REAL]
RETURNS [circle: Circle];
Returns a circle with center at "pt" and radius of "radius".
FillCircleFrom3Points:
PROC [p0, p1, p2: Point, circle: Circle]
RETURNS [linear:
BOOL];
"circle" now passes through the three points. If the points are roughly collinear, creates a large circle passing through p0 and p2.
CircleFrom3Points:
PROC [p0, p1, p2: Point]
RETURNS [circle: Circle, linear:
BOOL];
Returns a circle which passes through the three points. If the points are roughly collinear, creates a large circle passing through p0 and p2.
CircleMeetsLine: PROC [circle: Circle, line: Line] RETURNS [points: ARRAY [1..2] OF Point, hitCount: [0..2]];
CircleMeetsEdge: PROC [circle: Circle, edge: Edge] RETURNS [points: ARRAY [1..2] OF Point, hitCount: [0..2]];
CircleMeetsCircle: PROC [circle1, circle2: Circle] RETURNS [points: ARRAY [1..2] OF Point, hitCount: [0..2]];
CircleMeetsArc: PROC [circle: Circle, arc: Arc] RETURNS [points: ARRAY [1..2] OF Point, hitCount: [0..2]];
ArcMeetsLine: PROC [arc: Arc, line: Line] RETURNS [points: ARRAY [1..2] OF Point, hitCount: [0..2]];
ArcMeetsEdge: PROC [arc: Arc, edge: Edge] RETURNS [points: ARRAY [1..2] OF Point, hitCount: [0..2]];
ArcMeetsArc: PROC [arc1, arc2: Arc] RETURNS [points: ARRAY [1..2] OF Point, hitCount: [0..2]];
SignedCircleDistance: PROC [pt: Point, circle: Circle] RETURNS [d: REAL];
CircleDistance: PROC [pt: Point, circle: Circle] RETURNS [d: REAL];
PointProjectedOntoCircle:
PROC [pt: Point, circle: Circle]
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.
Finds any old point on line and returns it.
Returns the direction vector of line.
Arcs
CreateEmptyArc: PROC RETURNS [arc: Arc];
CopyArc: PROC [from: Arc, to: Arc];
FillArc: PROC [v0, v1, v2: Point, arc: Arc];
CreateArc: PROC [v0, v1, v2: Point] RETURNS [arc: Arc];
CirclePointOnArc:
PROC [pt: Point, arc: Arc]
RETURNS [
BOOL];
Assumes pt is on arc.circle. Is it on arc?
NearestEndpoint: PROC [pt: Point, arc: Arc] RETURNS [endpoint: Point];
DistanceSquaredToNearestEndpoint: PROC [pt: Point, arc: Arc] RETURNS [distanceSquared: REAL];
NearestPointOnArc:
PROC [pt: Point, arc: Arc]
RETURNS [onArc: Point];
The nearest point on arc.circle to pt, if the nearest point is on arc. Otherwise, the nearest endpoint.
DistancePointToArc:
PROC [pt: Point, arc: Arc]
RETURNS [distance:
REAL];
Distance[pt, NearestPointOnArc[pt, arc]].
DistanceSquaredPointToArc: PROC [pt: Point, arc: Arc] RETURNS [distanceSquared: REAL];
OnArc: PROC [pt: Point, arc: Arc] RETURNS [BOOL];
END.