ImplicitPrimitivesImpl.mesa
Copyright Ó 1985, 1990 by Xerox Corporation. All rights reserved.
Bloomenthal, September 6, 1992 12:01 pm PDT
Glassner, January 30, 1989 4:26:12 pm PST
DIRECTORY G3dBasic, G3dDraw, G3dTool, G3dVector, G3dMatrix, Imager, ImplicitPrimitives;
ImplicitPrimitivesImpl: CEDAR PROGRAM
IMPORTS G3dDraw, G3dVector, G3dMatrix
EXPORTS ImplicitPrimitives
~ BEGIN
Segment:  TYPE ~ G3dBasic.Segment;
Triple:  TYPE ~ G3dBasic.Triple;
Matrix:  TYPE ~ G3dMatrix.Matrix;
Context:  TYPE ~ Imager.Context;
Ellipsoid:  TYPE ~ ImplicitPrimitives.Ellipsoid;
EllipsoidRep: TYPE ~ ImplicitPrimitives.EllipsoidRep;
Ellipsoids
EllipsoidDraw: PUBLIC PROC [e: Ellipsoid, context: Context, view: G3dTool.View] ~ {
G3dDraw.Segment[context, e.x.p0, e.x.p1, view.camera.matrix, view.viewport];
G3dDraw.Segment[context, e.y.p0, e.y.p1, view.camera.matrix, view.viewport];
G3dDraw.Segment[context, e.z.p0, e.z.p1, view.camera.matrix, view.viewport];
};
EllipsoidMake: PUBLIC PROC [
p0, p1: Triple,
lengthScale, widthScale, heightScale: REAL ¬ 1.0,
refVec: Triple ¬ []]
RETURNS [e: Ellipsoid]
~ {
GetSegment: PROC [v: Triple, length: REAL] RETURNS [Segment] ~ {
v ¬ G3dVector.Mul[v, length];
RETURN[[G3dVector.Sub[mid, v], G3dVector.Add[mid, v]]];
};
ee: Ellipsoid ¬ e ¬ NEW[EllipsoidRep];
mid: Triple ¬ G3dVector.Midpoint[p0, p1];
dif: Triple ¬ G3dVector.Sub[p1, p0];
rv: Triple ¬ IF refVec # [] THEN refVec ELSE G3dVector.Ortho[dif];
chordLength: REAL ¬ G3dVector.Length[dif];
x: Triple ¬ G3dVector.Div[dif, chordLength];
y: Triple ¬ G3dVector.V90[x, refVec];
z: Triple ¬ G3dVector.Cross[x, y];
halfLength, halfWidth, halfHeight: REAL;
e.x ¬ GetSegment[x, halfLength ¬ 0.5*lengthScale*chordLength];
e.y ¬ GetSegment[y, halfWidth ¬ 0.5*widthScale*chordLength];
e.z ¬ GetSegment[z, halfHeight ¬ 0.5*heightScale*chordLength];
e.acc ¬ G3dVector.NearnessAccelerator[p0, p1];
e.m ¬ G3dMatrix.MakeFromTriad[x, y, z, mid, FALSE, e.m];
e.m ¬ G3dMatrix.Invert[e.m, e.m];
e.aTerm ¬ halfLength*halfLength;
e.bTerm ¬ halfWidth*halfWidth;
e.cTerm ¬ halfHeight*halfHeight;
};
EllipsoidValue: PUBLIC PROC [q: Triple, e: Ellipsoid] RETURNS [REAL] ~ {
p: Triple ¬ G3dMatrix.Transform[q, e.m];
RETURN[(p.x*p.x)/e.aTerm+(p.y*p.y)/e.bTerm+(p.z*p.z)/e.cTerm];
};
END.