SVLines3d.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Last edited by Bier on February 18, 1987
Contents: Procedures for performing geometric operations on lines and points in 3-space.
DIRECTORY
SV3d;
SVLines3d: CEDAR DEFINITIONS =
BEGIN
Edge3d: TYPE = SV3d.Edge3d;
Line3d: TYPE = SV3d.Line3d;
Matrix4by4: TYPE = SV3d.Matrix4by4;
Point3d: TYPE = SV3d.Point3d;
Vector3d: TYPE = SV3d.Vector3d;
Making Lines
CreateEmptyLine: PROC RETURNS [line: Line3d];
CopyLine: PROC [from: Line3d, to: Line3d];
These procedures allocate a new Line3d.
LineFromPoints: PROC [v1, v2: Point3d] RETURNS [line: Line3d];
LineFromPointAndVector: PROC [pt: Point3d, vec: Vector3d] RETURNS [line: Line3d];
LineNormalToLineThruPoint: PROC [line: Line3d, pt: Point3d] RETURNS [normalLine: Line3d];
line and pt determine a plane. Within that plane, compute the line that is perpendicular to line and passes throught pt.
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: Point3d, line: Line3d];
FillLineFromPointAndVector: PROC [pt: Point3d, vec: Vector3d, line: Line3d];
FillLineNormalToLineThruPoint: PROC [line: Line3d, pt: Point3d, normalLine: Line3d];
line and pt determine a plane. Within that plane, compute the line that is perpendicular to line and passes throught pt.
Making Edges
CreateEmptyEdge: PROC RETURNS [edge: Edge3d];
CopyEdge: PROC [from: Edge3d, to: Edge3d];
These procedures allocate a new edge.
CreateEdge: PROC [v1, v2: Point3d] RETURNS [edge: Edge3d];
EdgeTransform: PROC [fixed: Edge3d, transform: Matrix4by4] RETURNS [edge: Edge3d];
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: Point3d, edge: Edge3d];
FillEdgeTransform: PROC [fixed: Edge3d, transform: Matrix4by4, edge: Edge3d];
Direction and Distance for Lines
DirectionOfLine: PROC [line: Line3d] RETURNS [direction: Vector3d];
Returns the unit direction vector of line.
DistancePointToLine: PROC [pt: Point3d, line: Line3d] RETURNS [d: REAL];
DistanceLineToLine: PROC [l1, l2: Line3d] RETURNS [d: REAL];
DropPerpendicular: PROC [pt: Point3d, line: Line3d] RETURNS [projectedPt: Point3d];
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 using FillLineNormalToLineThruPoint above.
Distance for Edges
Comparing Edges to Points
NearEndpointToPoint: PROC [pt: Point3d, edge: Edge3d] RETURNS [endpoint: Point3d];
Distance2PointToEndpoint: PROC [pt: Point3d, edge: Edge3d] RETURNS [distanceSquared: REAL];
Computes the distance to each of the two endpoints and takes the smaller of the two.
NearEdgePointToPoint: PROC [pt: Point3d, edge: Edge3d] RETURNS [onEdge: Point3d];
Drop a perpendicular to the line of the edge. If the resulting point is on the edge, use it. Otherwise, find the nearest endpoint.
Distance2PointToEdge: PROC [pt: Point3d, edge: Edge3d] RETURNS [distanceSquared: REAL];
DistanceSquared[pt, NearestPointOnEdge[pt, edge]].
DistancePointToEdge: PROC [pt: Point3d, edge: Edge3d] RETURNS [distance: REAL];
OnEdge: PROC [pt: Point3d, edge: Edge3d] RETURNS [BOOL];
Returns TRUE if pt is within a very small distance from edge.
LinePointOnEdge: PROC [pt: Point3d, edge: Edge3d] RETURNS [BOOL];
Assumes pt is on the line that includes edge. Is it on edge itself?
Square root of the above.
Comparing Edges to Lines
DistanceLineToEdge: PROC [line: Line3d, edge: Edge3d] RETURNS [distance: REAL];
NearEdgePointToLine: PROC [line: Line3d, edge: Edge3d] RETURNS [edgePoint: Point3d];
DistanceAndPointLineToEdge: PROC [line: Line3d, edge: Edge3d] RETURNS [distance: REAL, edgePoint: Point3d];
I compute them both anyway, so if you need both, this will be faster.
END.