ImplicitEqtnsCmdImpl.mesa
Copyright Ó 1989, 1990 by Xerox Corporation. All rights reserved.
Bloomenthal, August 11, 1992 4:01 pm PDT
DIRECTORY Commander, Controls, G3dBasic, ImplicitDefs, ImplicitDesign, Rope;
ImplicitEqtnsCmdImpl: CEDAR PROGRAM
IMPORTS Controls, ImplicitDesign, Rope
~ BEGIN
CommandProc:  TYPE ~ Commander.CommandProc;
Tool:     TYPE ~ ImplicitDesign.Tool;
ROPE:     TYPE ~ Rope.ROPE;
ClickProc:   TYPE ~ Controls.ClickProc;
Various Algebraic Equations
Data:   TYPE ~ REF DataRep;
DataRep:  TYPE ~ RECORD [tool: Tool ¬ NIL, equation, slice: NAT ¬ 1];
EquationsCommand: CommandProc ~ {
s: Data ~ NEW[DataRep];
s.tool ¬ ImplicitDesign.MakeTool[
name: "Various Test Equations",
startProc: Start,
valueProc: Value,
client: [data: s],
extraButtons: LIST[Controls.ClickButton[EqtnRope[1], EquationCycle, s]],
toolSettings: [octreeType: converge, rootSize: 2.0, recurseMax: 5, threshold: 0.0]
];
};
Bound: PROC [p, min, max: G3dBasic.Triple] RETURNS [BOOL] ~ {
RETURN[p.x IN [min.x..max.x] AND p.y IN [min.y..max.y] AND p.z IN [min.z..max.z]];
};
Value: ImplicitDefs.ValueProc ~ {
Arnon2: PROC RETURNS [r: REAL] ~ {
x2: REAL ¬ point.x*point.x;
y2: REAL ¬ point.y*point.y;
z2: REAL ¬ point.z*point.z;
r ¬ 256.0*point.z*z2-128.0*x2*z2+144.0*point.x*y2*point.z+
16.0*x2*x2*point.z-27.0*y2*y2-4.0*point.x*x2*y2;
};
Arnon3: PROC RETURNS [r: REAL] ~ {
r ¬ 8.0*point.x*point.z-9.0*point.y*point.y-2.0*point.x*point.x*point.x;
};
s: Data ¬ NARROW[clientData];
IF G3dPlane.SideOfPlane[point, [-0.732, 0.037, -0.680, 0.586]] = negative THEN RETURN[-1.0];
SELECT s.equation FROM
1 => IF Bound[point, [-2.0, -2.0, -1.0], [2.0, 2.0, 1.0]]
THEN {
y2: REAL ¬ point.y*point.y;
RETURN[point.x*point.x-y2-point.y*y2];
}
ELSE RETURN[-1.0];
2 => value ¬ IF Bound[point, [-2.0, -2.0, -1.0], [2.0, 2.0, 1.0]]
THEN point.x*point.x-point.y*point.z*point.z ELSE -1.0;
3 => value ¬ IF Bound[point, [-2.0, -2.0, -2.0], [2.0, 2.0, 2.0]]
THEN (point.x*point.x*point.x-point.x)*(point.y*point.y*point.y-point.y)*(point.z*point.z*point.z-point.z)-0.5
ELSE -1.0;
4 => value ¬ point.y*point.y-4.0*point.x*point.z;
5 => value ¬ point.y*point.y-3.0*point.x*point.z;
6 => {
a: REAL ¬ point.y+2.0*point.x;
value ¬ a*a-3.0*point.x*(point.x+point.y+point.z);
};
7 => {
x2: REAL ¬ point.x*point.x;
y2: REAL ¬ point.y*point.y;
value ¬ y2*(point.z*point.z+y2-x2-1)+x2;
};
8 => value ¬ Arnon2[];
9 => value ¬ Arnon2[]*Arnon3[];
10 => value ¬ Arnon2[]*Arnon2[]+Arnon3[]*Arnon3[];
ENDCASE => value ¬ 0;
};
Start: ImplicitDefs.StartProc ~ {
d: Data ~ NARROW[clientData];
point ¬ IF d.equation = 3 THEN [1.273975, 1.273975, 1.273975] ELSE [0.0, 0.0, 0.0];
};
nEquations: NAT ¬ 10;
maxEquationLength: INT ¬ 0;
EqtnRope: PROC [id: NAT] RETURNS [r: ROPE] ~ {
r ¬ Rope.Concat["Eq ", SELECT id FROM
1 => "1: (Bajaj#1) x^2-y^2-y^3",
2 => "2: (Bajaj#2) x^2-yz^2",
3 => "3: (Bajaj#3) (x3-x)(y3-y)(z3-z)",
4 => "4: (TDMS#1) y^2-4xz",
5 => "5: (TDMS#2) y^2-3xz",
6 => "6: (TDMS#3) (y+2x)^2-3x(x+y+z)",
7 => "7: (Arnon#1) y^2z^2+y^4-x^2y^2-y^2+x^2",
8 => "8: (Arnon#2) 256z^3-128x^2z^2+144xy^2z+16x^4z-27y^4-4x^3y^2",
9 => "9: (Arnon#3) #8 OR 8xz-9y^2-2x^3",
10 => "10: (Arnon#4) #8 AND 8xz-9y^2-2x^3",
ENDCASE => NIL];
FOR n: INT IN [0..maxEquationLength-Rope.Length[r]] DO r ¬ Rope.Concat[r, " "]; ENDLOOP;
};
EquationCycle: ClickProc ~ {
d: Data ~ NARROW[clientData];
old: NAT ~ d.equation;
d.equation ¬ IF old = nEquations THEN 1 ELSE old+1;
Controls.ButtonRelabel[d.tool.tool3d.outerData, EqtnRope[old], EqtnRope[d.equation]];
};
Start Code
FOR n: NAT IN [1..nEquations] DO
maxEquationLength ¬ MAX[maxEquationLength, Rope.Length[EqtnRope[n]]];
ENDLOOP;
ImplicitDesign.Register["Equations", EquationsCommand, "test various equations."];
END.