Boolean Operations and Floating Point Recommendations

Hello,

I am getting failures when performing boolean operations like difference between shapes that have the same dimensions, e.g., two cylinders intersecting. Is there a recommended way to handle this situation? I was looking for an epsilon value to handle floating point differences, but I haven't found any documentation.

A minimal example to reproduce is:

        public List<Entity>? Create()
        {
            var shapes = new List<Entity>();

            var tube1 = CreateTube(6.625, 6, 12, System.Drawing.Color.Red);

            // Changing the OD and ID by a fuzz factor makes the difference operation work
            var tube2 = CreateTube(6.625, 6, 16, System.Drawing.Color.Green);
            tube2.Rotate(Math.PI / 2, Vector3D.AxisX);
            tube2.Translate(0, 8.0, 0);

            var differenceBodies = Brep.Difference(tube1, tube2);

            if (differenceBodies != null)
            {
                foreach (var body in differenceBodies)
                {
                    shapes.Add(body);
                    body.Color = System.Drawing.Color.Blue;
                }
            }

            return shapes;
        }

        public Brep? CreateTube(double od, double id, double length, System.Drawing.Color color)
        {
            var cylOd = Brep.CreateCylinder(od, length);
            var cylId = Brep.CreateCylinder(id, length);

            var tube = Brep.Difference(cylOd, cylId).FirstOrDefault();

            if (tube != null)
            {
                tube.ColorMethod = colorMethodType.byEntity;
                tube.Color = color;
            }

            return tube;
        }

The above snippet fails to perform a difference operation (null returned). If I change the diameter of one of the tubes by a small epsilon amount, the above operations succeed as expected.

Is there a recommended way to deal with this situation?

Thanks!

0

Comments

1 comment
Date Votes
  • Hello Devin,

    Please provide us every single problematic case via support ticket.

    0

Please sign in to leave a comment.

Didn't find what you were looking for?

New post