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; CreateEmptyLine: PROC RETURNS [line: Line]; CopyLine: PROC [from: Line, to: Line]; 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]; 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]; 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]; PointOnLine: PROC [line: Line] RETURNS [pt: Point]; DirectionOfLine: PROC [line: Line] RETURNS [direction: Vector]; CreateEmptyEdge: PROC RETURNS [edge: Edge]; CopyEdge: PROC [from: Edge, to: Edge]; 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]; LinePointOnEdge: PROC [pt: Point, edge: Edge] RETURNS [BOOL]; 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]; DistancePointToEdge: PROC [pt: Point, edge: Edge] RETURNS [distance: REAL]; DistanceSquaredPointToEdge: PROC [pt: Point, edge: Edge] RETURNS [distanceSquared: REAL]; OnEdge: PROC [pt: Point, edge: Edge] RETURNS [BOOL]; 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]; 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. β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 Lines 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. 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. Makes a new line that results by transforming fixed by transform. Computations on Lines 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. Edges 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. These procedures allocate a new edge. Computations on Edges Assumes pt is on edge.line. Is it on edge? The nearest point on edge.line to pt, if the nearest point is on edge. Otherwise, the nearest endpoint. Distance[pt, NearestPointOnEdge[pt, edge]]. Returns TRUE if pt is at a very small distance from edge. Points RAYS -- Used by GGShapes to draw infinite lines (e.g. to do manual clipping) ΚΙ˜Icode™ Kšœ0™0Kšœ5™5šœ]™]K™&—K˜šΟk ˜ Kšœ#˜#—K˜Kšœ œ œ˜Kš˜˜Kšœœ˜!Kšœœ˜Kšœœ˜Kšœœ˜Kšœœ˜#K˜K˜—K™K˜KšΟnœœœ˜,Kšžœœ˜'˜Kšœ±™±—Kšžœœ˜5Kšžœœ&˜FKšžœœ(œ˜XKšžœœœ˜GKšžœœ+˜NKšžœœœ˜FKšžœœœ˜GšžœœK˜bKšœ{™{—˜K™%—Kšžœœœ˜:Kšžœœœ˜LKšžœœ(œœ˜]Kšžœœœœ˜LKšžœœœ˜SKšžœœœœ˜KKšžœœœœ˜Lšž œœ?œ˜rKšœA™A—˜K™—Kšž œœœ!œ˜XKš žœœœœ œ˜HKšž œœœœ˜YKšž œœœœ˜OK˜Kšžœœœœ˜DKšž œœœœ˜>šžœœœ˜SšœD™DKšœR™R——šž œœœ ˜3K™+—šžœœœ˜?K™%K˜—K™™K˜—K˜Kšžœœœ˜,šžœœ˜'Kšœ±™±—K˜Kšžœœ˜,KšžœœK˜bK˜Kšž œœœ˜7Kšž œœ?œ˜g˜K™%—K˜K™K™šžœœœœ˜>Kšœ+™+—Kšžœœœ˜IKš ž œœœœœ˜fšžœœœ˜IKšœh™h—šžœœœ œ˜LKšœ+™+—Kšžœœœœ˜Zšžœœœœ˜4K™9—K™K™K™Kšžœœœ œ˜EKšžœœœ œ˜LKšžœœ œœ˜[K˜KšœL™LK˜Kšž œœ'œ ˜IKšžœœœ ˜=Kšžœœ$œœ œ œœœ˜qKšžœœœœ˜=K˜Kšœ˜—…—²]