Misc3dImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, February 18, 1986 3:39:24 pm PST
DIRECTORY Misc3d, Matrix3d, RealFns, Vector3d;
Misc3dImpl: CEDAR PROGRAM
IMPORTS Matrix3d, RealFns, Vector3d
EXPORTS Misc3d
~ {
Matrix: TYPE ~ Matrix3d.Matrix;
Triple: TYPE ~ Vector3d.Triple;
Frame: TYPE ~ Misc3d.Frame;
MakeFrame: PUBLIC PROC [v: Triple] RETURNS [Frame] ~ {
n: Triple ← Vector3d.Ortho[v];
RETURN[[v, n, Vector3d.Cross[v, n]]];
};
Basis: PUBLIC PROC [v, vv, rv: Triple] RETURNS [n, b: Triple] ~ {
dot: REAL;
vv ← Vector3d.Normalize[vv];
v ← Vector3d.Normalize[v];
rv ← Vector3d.Normalize[rv];
dot ← Vector3d.Dot[v, vv];
IF ABS[dot] > 0.9999 THEN {        -- tangents v, vv colinear
n ← IF dot > 0.0 THEN rv ELSE [-rv.x, -rv.y, -rv.z];
n ← Vector3d.V90[v, n];       -- ensure orthogonality
}
ELSE {
a: REAL ← RealFns.ArcTanDeg[RealFns.SqRt[1.0-dot*dot], dot];
axis: Triple ← Vector3d.Cross[v, vv];
n ← Vector3d.Normalize[Vector3d.RotateAbout[rv, axis, a]]; -- incremental kludge
};
b ← Vector3d.Normalize[Vector3d.Cross[v, n]];
};
RefMatrix: PUBLIC PROC [p, x, y, z: Triple, s, t: REAL, out: Matrix←NIL] RETURNS [Matrix] ~ {
IF ABS[t] > 0.001 THEN {
out ← Matrix3d.MakePureRotate[z, t,, out];
x ← Matrix3d.TransformVec[x, out];
y ← Matrix3d.TransformVec[y, out];
};
RETURN[Matrix3d.LocalScale[Matrix3d.MakeFromTriad[x, y, z, p], s, out]];
};
}.