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;
};