Vector3d.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Bloomenthal, February 19, 1986 10:16:46 am PST
DIRECTORY Rope, Vector2;
Vector3d: CEDAR DEFINITIONS
~ BEGIN
Pair:   TYPE ~ Vector2.VEC;
Triple:  TYPE ~ RECORD [x, y, z: REAL];
Quad:   TYPE ~ RECORD [x, y, z, w: REAL];
Line:   TYPE ~ RECORD [base, axis: Triple];
nullTriple: Triple ~ [0.0, 0.0, 0.0];
Standard Geometric Operations on 3d vectors or points
Null: PROC [v: Triple] RETURNS [BOOL];
Returns TRUE iff v is the nullTriple.
Equal: PROC [v1, v2: Triple, tol: REAL ← 0.001] RETURNS [BOOL];
Returns TRUE iff v1 = v2, to within tol tolerance.
Add: PROC [v1, v2: Triple] RETURNS [Triple];
Vector additon: return v1+v2.
Sub: PROC [v1, v2: Triple] RETURNS [Triple];
Vector subtraction: return v1-v2.
Neg: PROC [v: Triple] RETURNS [Triple];
Vector negation: return -v.
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.
Combine: PROC [v1: Triple, s1: REAL, v2: Triple, s2: REAL] RETURNS [Triple];
return s1*v1+s2*v2.
Mag: PROC [v: Triple] RETURNS [REAL];
Vector length: return SqRt[v.v] = |v|.
SameMag: PROC [v1, v2: Triple] RETURNS [Triple];
Return v2 adjusted to be same magnitude as v1.
Square: 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.
LinePoint: PROC [p: Triple, l: Line] RETURNS [Triple];
Return point closest to p on l.
Normalize: PROC [v: Triple] RETURNS [Triple];
vector normalization: return v/|v|.
Ray: PROC [l: Line, d: REAL] RETURNS [Triple];
Return l.base+d*l.axis.
Project: PROC [v1, v2: Triple] RETURNS [Triple];
Return the vector projection of v1 onto v2.
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.
Collinear: PROC [p1, p2, p3: Triple, tol: REAL ← 0.01] RETURNS [BOOL];
Return TRUE iff the three points are colinear, to within tol tolerance.
VecsCoplanar: PROC [v1, v2, v3: Triple, tol: REAL ← 0.005] RETURNS [BOOL];
Return TRUE iff the three vectors are coplanar.
PsCoplanar: PROC [p1, p2, p3, p4: Triple, tol: REAL ← 0.005] RETURNS [BOOL];
Return TRUE iff the four points are coplanar, ie., all within tol distance of a plane.
Parallel: PROC [v1, v2: Triple, tol: REAL ← 0.005] RETURNS [BOOL];
Return TRUE iff the two vectors are parallel, to within tol tolerance.
Perp: PROC [v1, v2: Triple, tol: REAL ← 0.005] RETURNS [BOOL];
Return TRUE iff the two vectors are perpendicular, to within tol tolerance.
PtOnLine: PROC [p: Triple, l: Line, tol: REAL ← 0.005] RETURNS [BOOL];
Return TRUE iff p is within tol of the l.
Scalar Operations
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.
Component-wise Operations
MulC: PROC [v1, v2: Triple] RETURNS [Triple];
Return v1*v2.
DivC: PROC [v1, v2: Triple] RETURNS [Triple];
Return v1/v2; component division not performed if v2 component = 0.
Miscellaneous Operations
PolarFromCartesian: PROC [cartesian: Triple] RETURNS [Triple];
Return the polar equivalent of the input cartesian vector.
CartesianFromPolar: PROC [polar: Triple] RETURNS [Triple];
Return the cartesian equivalent of the input polar vector.
END.