I came across a simple example for which Boolean difference completely fails. Changing the tolerance settings does not help. The solids are clean and simple. Obviously there are workarounds for this, but I decided to post this to help tracking down the problem in Boolean difference. Please find attached the example.
Why are you working with such high file tolerances? That’s 1/1000 of a micron, very few manufacturing process can even hold one micron. For objects of that size, that tolerance setting basically only going to slow things down and may cause operations to fail.
Was this object created in Rhino or elsewhere? As Menno said, there are edges that have been pulled completely out of tolerance - by 5-6 mm in some cases, so it would be good to know how it was made in the first place.
The reason I am working with a very low value for the absolute tolerance was to achieve a model as clean as possible, because I knew I would have to do a lot of Boolean operations later on. All of the objects in my example where created inside Rhino, using the same absolute tolerance setting of 1e-6.
I uploaded another file containing the object before any Boolean operation. The tolerance shown by the List command is already quite high for some edges in my opinion, way to high given the absolute tolerance setting I am using. (On another note it would be interesting to know how the tolerances shown by the List command are defined exactly.) Doing the Boolean difference based on this object, the tolerance explodes after the Boolean operation. Subtracting both red objects parallel does not work, only if done serially in a specific order. In any case no further Boolean operations can be done afterwards.
Again, how was the green object made (before boolean) ? If you explode, rebuild edges and re-join, it does not join up as closed, the edges are way out of tolerance. This does not appear to be a simple extrusion, so how did you create it to have edges that bad?
If I extract a border, and I extrude that, the boolean differences work fine…
The green solid consists of 4 planar surfaces (top and bottom, sides), and two curved surfaces (front and back). It was created by reciprocally trimming the initial (large) surfaces with each other, then joining them to a solid. All of these operations were carried out using an absolute tolerance of 1e-6. What I don’t get is how the edges can become that bad, because all of them are intersections created at this very low tolerance.
What’s odd here is that I am unable to change the file tolerance back to something reasonable such as 0.001. (that looks like a bug - not in your file though, wonder if anyone else sees that…)
Again, your very high tolerance value is probably the cause here, coupled with the fact that your objects are very far from the origin. The floating point math involved may not be able to arrive at a successful edge join under these conditions.
If I copy your object to a new file (as I can’t seem to change the tolerances in an open file here) with an absolute tolerance of 0.001, untrim, retrim and rejoin all using that tolerance, everything works fine including the BooleanDifference, even that far from the origin.
You are working under the misconception that setting the tolerance higher will result in a more accurate file. That is not necessarily the case and can actually cause problems later on, as the Wiki article suggests.
From the wiki page:
In general you should keep the absolute tolerance setting in the range
of 0.01 to 0.0001, and never set it below 1.0e-5. If you need tighter
tolerance, use smaller units instead.
Many thanks for your feedback. I also worked on tracking down the problem, and found out the following:
The inaccuracy is introduced when trimming the planar top surface using one of the curved side surfaces. This is being done in a RhinoScript using Rhino.TrimBrep. The trimmed surface resulting from this operation already has a very high tolerance (>1mm) along one of its edges. Strangely the joining of surfaces, which follows after the trimming of all 6 faces making up the solid, does not care about this huge tolerance and just joins everything into a solid. I assume this happens because the edge curves are actually correct and match each other within tolerance.
I am sure now that there is a bug in Rhino.TrimBrep. It doesn’t occur very often because I am using this procedure on hundreds of these elements, and I had this problems only regarding two of them. Interestingly it only occurs when trimming planar surfaces. I am using the following workaround now: After calling Rhino.TrimBrep on the planar surface, I duplicate the boundary curve and recreated a planar surface from it using Rhino.AddPlanarSrf.
Well, I suppose it could be a bug in Rhino.TrimBrep()… However, I still don’t see why it works with the normal native Rhino commands (if you lower the file tolerance) and not with RhinoCommon. In principle, it is calling the same code behind the scenes… It is possible that TrimBrep() is not paying attention to the programmed tolerance as it is supposed to and is instead using the file tolerance, which might explain the failure.
This is not necessarily true for all commands, I recall multiple discussions in where a developer wants to “duplicate” the behavior of a command, and the response of RMA being that this is not possible because the native Rhino command has completely different code than the similar code in RhinoCommon (e.g. Using CreatePatch in RhinoCommon without a starting surface)