Open raphaelsetin opened 3 years ago
I cannot reproduce on master:
w = cq.importers.importStep('cube_grid.step')
c = w.val()
bb = c.BoundingBox()
bb.xlen, bb.ylen, bb.zlen
gives me:
(145.0, 145.00000000000003, 10.0)
gives me:
(145.0, 145.00000000000003, 10.0)
+1, installed through nix package manager instead of Conda. Both OCP/OCCT v7.5.1 and v7.4.
Hey @adam-urbanczyk and @marcus7070, thank you for the quick feedback on this! This was definitely strange because as far as I can recall, CADQuery was always accurate for me in the past.
So after some tests, I was able to find the bug, which seems to be non-user related. Basically, whenever we get the CADQuery workplane and just get the bounding box, everything works as expected. But if we export the workplane to another format, such as STL
, then getting the bounding box afterwards is less accurate. Volume seems to be unaffected as we can see from this test.
import cadquery as cq
wp = cq.importers.importStep('/tmp/cube_grid.step.stp')
wpVal = wp.val()
bBox = wpVal.BoundingBox()
volume = wpVal.Volume()
print('Before:', bBox.xlen, bBox.ylen, bBox.zlen)
print('Before:', volume)
cq.exporters.export(wp, '/tmp/test.stl')
bBox = wpVal.BoundingBox()
volume = wpVal.Volume()
print('After:', bBox.xlen, bBox.ylen, bBox.zlen)
print('After:', volume)
Before: 145.0 145.00000000000003 10.0
Before: 100000.00000000065
After: 149.00000028 149.00000028000002 14.000000280000002
After: 100000.00000000065
It seems that exporting the workplane messes up with the tolerance settings, though I haven't tested this for sure; but it's definitely something along these lines.
Confirmed
I've came across this problem today, when I saw that the bounding box measurements of the models in which I imported (in
.STP
format) to CADQuery were off by a few millimeters -- depending on the model this could be higher. After some research and reading throughout the repo, I saw issues #7, #74, #79, and #167, in which weren't successful at fixing this problem.I tried to tweak the tolerance using all the examples provided in these discussions (to no avail), such as:
cadquery.occ_impl.geom.TOL = 0.00001
cadquery.BoundBox._fromTopoDS(cube.val().wrapped, tol=0.00001)
cube.val().BoundingBox(tolerance=0.00001)
A good example file to use is this cube_grid.step. Also, for comparison, here are some values from CADQuery, PythonOCC, and FreeCAD:
As you can see, the CADQuery implementation of the bounding box function is clearly flawed in precision. What is strange to me is how well the volume implementation is (super precise as the other libraries), but our bounding box implementation is not.