I make a CAD program using eyeshot (2022/2023). From the very beginning I've been facing problems with Boolean operations, in this case the difference operation. To illustrate my problem I prepared a demo in which this problem occurs.
From the red I-Beam figure, I want to cut a blue figure.
After the difference operation I get this result.

As you can see, I get strange walls in a place where they shouldn't be.
protected override void OnContentRendered(EventArgs e)
{
design1.ActiveViewport.Grid.AutoSize = true;
design1.ActiveViewport.Grid.Step = 100;
design1.Layers[0].Color = System.Drawing.Color.FromArgb(127, 127, 127);
//Creating I-Beam Brep
Brep bar = IBeam(590, 300, 13, 25, 27, 500);
//design1.Entities.Add(bar, design1.Layers[0].Name, System.Drawing.Color.Crimson);
//Creating box Brep
Brep box = DrawBox();
box.Translate(0, -1, 0.5);
//design1.Entities.Add(box, design1.Layers[0].Name, System.Drawing.Color.Blue);
//Creating difference
Brep[] diffArray = Brep.Difference(bar, box);
if (diffArray != null)
{
Brep diff = diffArray.FirstOrDefault();
design1.Entities.Add(diff);
}
design1.ZoomFit();
design1.Invalidate();
base.OnContentRendered(e);
}
private Brep DrawBox()
{
double height = 142;
double width = 144;
Point3D p1 = new Point3D(0, 0, 0);
Point3D p2 = new Point3D(0, 0, -height);
Point3D p3 = new Point3D(width, 0, -height);
Point3D p4 = new Point3D(width, 0, 0);
List<ICurve> curves = new List<ICurve>() { new Line(p1, p2), new Line(p2, p3), new Line(p3, p4), new Line(p4, p1) };
CompositeCurve curve = new CompositeCurve(curves, false);
devDept.Eyeshot.Entities.Region reg = new devDept.Eyeshot.Entities.Region(curve, devDept.Geometry.Plane.XZ, true);
Brep brep = reg.ExtrudeAsBrep(-26);
return brep;
}
private static Brep IBeam(double w, double t, double h, double r, double j, double extrudeLength = 500.0)
{
CompositeCurve curve = IBeamStraightSketch(w, t, h, r, j);
devDept.Eyeshot.Entities.Region reg = new devDept.Eyeshot.Entities.Region(curve, devDept.Geometry.Plane.YZ, true);
Brep brepBeam = reg.ExtrudeAsBrep(extrudeLength);
brepBeam.Rotate(Utility.DegToRad(90.0), Vector3D.AxisX, Point3D.Origin);
brepBeam.Translate(0, 0, -t);
return brepBeam;
}
public static CompositeCurve IBeamStraightSketch(double w, double h, double t, double p, double r)
{
double moveY = (h - t) / 2;
if (r \< 1) r = t;
Point3D p1 = new Point3D(0, h);
Point3D p2 = new Point3D(p, h);
Point3D p3 = new Point3D(p, h - moveY + r);
Point3D p4ArcTopLeftCenter = new Point3D(p + r, h - moveY + r);
Point3D p7ArcTopRightCenter = new Point3D(w - p - r, h - moveY + r);
Point3D p8 = new Point3D(w - p, h - moveY + r);
Point3D p9 = new Point3D(w - p, h);
Point3D p10 = new Point3D(w, h);
Point3D p11 = new Point3D(w, 0);
Point3D p12 = new Point3D(w - p, 0);
Point3D p13 = new Point3D(w - p, moveY - r);
Point3D p14ArcBottomRightCenter = new Point3D(w - p - r, moveY - r);
Point3D p17ArcBottomLeftCenter = new Point3D(p + r, moveY - r);
Point3D p18 = new Point3D(p, moveY - r);
Point3D p19 = new Point3D(p, 0);
Point3D p20 = new Point3D(0, 0);
Line line1Left = new Line(p3, p2);
Line line2Left = new Line(p2, p1);
Line line3Left = new Line(p1, p20);
Line line4Left = new Line(p20, p19);
Line line5Left = new Line(p19, p18);
Line line1Right = new Line(p8, p9);
Line line2Right = new Line(p9, p10);
Line line3Right = new Line(p10, p11);
Line line4Right = new Line(p11, p12);
Line line5Right = new Line(p12, p13);
Arc aTopLeftIn = new Arc(p4ArcTopLeftCenter, r, Utility.DegToRad(-180), Utility.DegToRad(-90));
Arc aTopRightIn = new Arc(p7ArcTopRightCenter, r, Utility.DegToRad(-90), Utility.DegToRad(0));
Arc aBottomRightIn = new Arc(p14ArcBottomRightCenter, r, Utility.DegToRad(0), Utility.DegToRad(90));
Arc aBottomLeftIn = new Arc(p17ArcBottomLeftCenter, r, Utility.DegToRad(90), Utility.DegToRad(180));
Line lMiddleTop = new Line(aTopLeftIn.EndPoint, aTopRightIn.StartPoint);
Line lMiddleBottom = new Line(aBottomRightIn.EndPoint, aBottomLeftIn.StartPoint);
List<ICurve> lstElements = new List<ICurve>()
{
aTopLeftIn,
lMiddleTop,
aTopRightIn,
line1Right,
line2Right,
line3Right,
line4Right,
line5Right,
aBottomRightIn,
lMiddleBottom,
aBottomLeftIn,
line1Left,
line2Left,
line3Left,
line4Left,
line5Left
};
CompositeCurve ccIBeam = new CompositeCurve(lstElements);
ccIBeam.Rotate(Utility.DegToRad(90.0), Vector3D.AxisY, Point3D.Origin);
return ccIBeam;
}
When I move the box figure in the Y-axis by 0.01 everything cuts out correctly and looks like below.
Unfortunately, this is not the solution to my problem. I can't move the components around until they finally graciously agree to cut correctly. I guess that the problem is that one of the I-Beam planes and one of the box planes lie in the same place. When I do a much simpler example of cutting two boxes between them, even if their walls lie in the same places such a problem does not occur there.
I feel that I've tried everything I can. I've tried using brep methods such as Regen(), Rebuild(), FixTopology(), UpdateBoundingBox(). They didn't work for my problem. The only solution I have been able to work out is to use on box scaling by 0.001 box.Scale(1.001, 1.001, 1.001); However, I feel that this is not a comprehensive solution to this problem and sooner or later I will run into more cases where the problem will recur.


