Vector3d.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Bloomenthal, February 26, 1987 7:06:20 pm PST
DIRECTORY Vector2;
Vector3d: CEDAR DEFINITIONS
~ BEGIN
Standard Geometric Operations on 3d vectors or points
Types and Constants
RealSequence:  TYPE ~ REF RealSequenceRep;
RealSequenceRep: TYPE ~ RECORD [
        length: CARDINAL ← 0,
        element: SEQUENCE maxLength: CARDINAL OF REAL
        ];
Pair:     TYPE ~ Vector2.VEC;
PairSequence:  TYPE ~ REF PairSequenceRep;
PairSequenceRep: TYPE ~ RECORD [
        length: CARDINAL ← 0,
        element: SEQUENCE maxLength: CARDINAL OF Pair
        ];
Triple:    TYPE ~ RECORD [x, y, z: REAL];
TripleSequence:  TYPE ~ REF TripleSequenceRep;
TripleSequenceRep: TYPE ~ RECORD [
        length: CARDINAL ← 0,
        element: SEQUENCE maxLength: CARDINAL OF Triple
        ];
Quad:     TYPE ~ RECORD [x, y, z, w: REAL];
Line:     TYPE ~ RECORD [base, axis: Triple];
MinMax:    TYPE ~ RECORD [min, max: Triple];
origin:    Triple ~ [0.0, 0.0, 0.0];
xAxis:     Triple ~ [1.0, 0.0, 0.0];
yAxis:    Triple ~ [0.0, 1.0, 0.0];
zAxis:     Triple ~ [0.0, 0.0, 1.0];
Basic Operations on a Single Vector
Null: PROC [v: Triple] RETURNS [BOOL];
Returns TRUE iff v is the origin.
Negate: PROC [v: Triple] RETURNS [Triple];
Vector negation: return -v.
Normalize: PROC [v: Triple] RETURNS [Triple];
Vector normalization: return v/|v|.
Unitize: PROC [v: Triple] RETURNS [Triple];
Same as Normalize.
Mul: PROC [v: Triple, s: REAL] RETURNS [Triple];
Vector scalar multiplication: return s*v.
Div: PROC [v: Triple, s: REAL] RETURNS [Triple];
Vector scalar division: return v/s; division not performed if s = 0.
Basic Operations on Two Vectors
Add: PROC [v1, v2: Triple] RETURNS [Triple];
Vector additon: return v1+v2.
Sub: PROC [v1, v2: Triple] RETURNS [Triple];
Vector subtraction: return v1-v2.
Equal: PROC [v1, v2: Triple, epsilon: REAL ← 0.001] RETURNS [BOOL];
Returns TRUE iff v1 = v2, to within epsilon.
Dot: PROC [v1, v2: Triple] RETURNS [REAL];
Vector dot product: return v1.v2.
Cross: PROC [v1, v2: Triple] RETURNS [Triple];
Right handed vector cross product: v1 v2.
Average: PROC [v1: Triple, v2: Triple] RETURNS [Triple];
Return 0.5*(v1+v2).
Combine: PROC [v1: Triple, s1: REAL, v2: Triple, s2: REAL] RETURNS [Triple];
Return s1*v1+s2*v2.
Ray: PROC [l: Line, d: REAL] RETURNS [Triple];
Return l.base+d*l.axis.
MulVectors: PROC [v1, v2: Triple] RETURNS [Triple];
Return v1*v2.
DivVectors: PROC [v1, v2: Triple] RETURNS [Triple];
Return v1/v2; component division not performed if v2 component = 0.
Length and Distance Operations
Length: PROC [v: Triple] RETURNS [REAL];
Vector length: return SqRt[v.v] = |v|.
SquareLength: PROC [v: Triple] RETURNS [REAL];
Vector length squared: return |v||v| (same as Dot[v, v]).
Distance: PROC [p1, p2: Triple] RETURNS [REAL];
Distance between two points.
SquareDistance: PROC [p1, p2: Triple] RETURNS [REAL];
Distance squared between two points.
SameLength: PROC [v1, v2: Triple] RETURNS [Triple];
Return v2 adjusted to be same magnitude as v1.
Parallelness, Coplanarity and Collinearity Tests
Collinear: PROC [p1, p2, p3: Triple, epsilon: REAL ← 0.01] RETURNS [BOOL];
Return TRUE iff the three points are colinear, to within epsilon.
VecsCoplanar: PROC [v1, v2, v3: Triple, epsilon: REAL ← 0.005] RETURNS [BOOL];
Return TRUE iff the three vectors are coplanar.
PsCoplanar: PROC [p1, p2, p3, p4: Triple, epsilon: REAL ← 0.005] RETURNS [BOOL];
Return TRUE iff the four points are coplanar, ie., all within epsilon distance of a plane.
Parallel: PROC [v1, v2: Triple, epsilon: REAL ← 0.005] RETURNS [BOOL];
Return TRUE iff the two vectors are parallel, to within epsilon.
Perpendicular: PROC [v1, v2: Triple, epsilon: REAL ← 0.005] RETURNS [BOOL];
Return TRUE iff the two vectors are perpendicular, to within epsilon.
Nearness Operations
LinePoint: PROC [p: Triple, l: Line] RETURNS [Triple];
Return point closest to p on l.
Project: PROC [v1, v2: Triple] RETURNS [Triple];
Return the vector projection of v1 onto v2.
PtOnLine: PROC [p: Triple, l: Line, epsilon: REAL ← 0.005] RETURNS [BOOL];
Return TRUE iff p is within epsilon of the l.
Simple Geometric Operations
V90: PROC [v0, v1: Triple] RETURNS [Triple];
Return vector orthogonal to v0 and in plane of v0 and v1; v0 and v1 presumed unitized.
Ortho: PROC [v: Triple, crosser: Triple ← [0.0, 0.0, 1.0]] RETURNS [Triple];
Return a vector orthonormal to both v and crosser and of the same magnitude as v; if v =
crosser, an arbitrary crosser is chosen.
RotateAbout: PROC [v, axis: Triple, a: REAL, degrees: BOOLTRUE] RETURNS [Triple];
Return v rotated around axis by a.
Polar/Cartesian Coordinates
PolarFromCartesian: PROC [cartesian: Triple] RETURNS [Triple];
Return the polar equivalent of the input cartesian vector.
The returned triple's x, y, and z fields correspond to longitude, lattitude, and magnitude.
CartesianFromPolar: PROC [polar: Triple] RETURNS [Triple];
The input triple's x, y, and z fields correspond to longitude, lattitude, and magnitude.
Return the cartesian equivalent of the input polar vector.
Copying Operations
CopyRealSequence: PROC [reals: RealSequence] RETURNS [RealSequence];
Return a copy of the input sequence of reals.
CopyPairSequence: PROC [pairs: PairSequence] RETURNS [PairSequence];
Return a copy of the input sequence of pairs.
CopyTripleSequence: PROC [triples: TripleSequence] RETURNS [TripleSequence];
Return a copy of the input sequence of triples.
Miscellany
ArcCos: PROC [cos: REAL, degrees: BOOLTRUE] RETURNS [REAL];
Return the angle in degrees if degrees TRUE, else in radians.
CosineBetween: PROC [v0, v1: Triple] RETURNS [REAL];
Return the cosine of the angle between the two vectors.
AngleBetween: PROC [v0, v1: Triple, degrees: BOOLTRUE] RETURNS [REAL];
Return the angle (in degrees if degrees TRUE, else in radians) between the two vectors.
MinMaxOfTriples: PROC [triples: TripleSequence] RETURNS [MinMax];
Return the bounding triples of the sequence.
END.