BoundBox too small

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Thomas_A
Posts: 2
Joined: Sat Feb 22, 2020 12:05 am

BoundBox too small

Post by Thomas_A »

I am surprised by the behavior of the following simple script

Code: Select all

obj = App.ActiveDocument.addObject("Part::Torus","Torus")
App.ActiveDocument.recompute()
obj.Shape.BoundBox
where the last command has the following output:

Code: Select all

BoundBox (-11.9818, -11.9954, -1.98542, 12, 11.9954, 1.98542)
Given that the default radii of the torus are 10 and 2, the bounding box must be at least of the size

Code: Select all

BoundBox (-12., -12., -2., 12., 12., 2.)
I would not care if it is bigger (this would just make it more inefficient) but it being too small is a huge problem for my code.

Is this intended behavior?

(I compiled FreeCAD from the current state of its git repository - so my version should be up-to-date.)
User avatar
Hannu
Posts: 130
Joined: Fri Sep 11, 2015 4:12 pm
Location: Strängnäs, Sweden - 1hr drive west from Stockholm

Re: BoundBox too small

Post by Hannu »

FWIW:

Code: Select all

>>> ### Begin command Std_New
>>> App.newDocument("Unnamed")
>>> # App.setActiveDocument("Unnamed")
>>> # App.ActiveDocument=App.getDocument("Unnamed")
>>> # Gui.ActiveDocument=Gui.getDocument("Unnamed")
>>> Gui.activeDocument().activeView().viewDefaultOrientation()
>>> ### End command Std_New
>>> Gui.runCommand('Std_OrthographicCamera',1)
>>> obj = App.ActiveDocument.addObject("Part::Torus","Torus")
>>> App.ActiveDocument.recompute()
1
>>> obj.Shape.BoundBox
BoundBox (-12, -12, -1.98542, 12, 12, 1.98542)
>>> 

Now, how exact does things need to be?
Screenshot from 2020-02-22 09-14-02.png
Screenshot from 2020-02-22 09-14-02.png (21.89 KiB) Viewed 513 times

That is a 7.3 ‰ (per mille) difference; should we expect a "perfect" measurement?

Code: Select all

>>> round(1.98542,3)
1.985
>>> round(1.98542,2)
1.99
>>> round(1.98542,1)
2.0
>>> 
OS: Ubuntu 16.04.6 LTS (Unity/ubuntu)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19. <<--?? The latest daily, updated just an hour ago.
Build type: Release
Python version: 3.5.2
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
/Hannu - engineer & mild :geek:
- Embedded, Computer, Software, Electronic, Fault analysis. A&D Photography http://flickr.com/arkane
- Mechanics, FDM 3D-prints, Solder, Lathe, Mill, Weld -work. ISO Audits, Claim, Deviation, Corrective action
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: BoundBox too small

Post by openBrain »

This is due to Shape tessellation settings. ;)
FreeCAD shapes are BREP and so BoundBox may vary depending on tessellation settings (this is especially true on curved objects).
Look following snippet :

Code: Select all

>>> obj = App.ActiveDocument.addObject("Part::Torus","Torus")
>>> App.ActiveDocument.recompute()
1
>>> obj.Shape.BoundBox
BoundBox (-12, -12, -1.98542, 12, 12, 1.98542)
>>> obj.ViewObject.Deviation = 0.02
>>> obj.ViewObject.AngularDeflection = 1
>>> App.ActiveDocument.recompute()
0
>>> obj.Shape.BoundBox
BoundBox (-11.9983, -11.9996, -2, 12, 11.9996, 2)
I think in this case actually only Deviation plays a role but I'm not really a specialist. ;)
Thomas_A
Posts: 2
Joined: Sat Feb 22, 2020 12:05 am

Re: BoundBox too small

Post by Thomas_A »

Thanks for the elaborations. I am new to FreeCAD and I now understand where the problem comes from.
Hannu wrote: Sat Feb 22, 2020 8:06 am That is a 7.3 ‰ (per mille) difference; should we expect a "perfect" measurement?
Perhaps my background in computer graphics is not appropriate here but in my conception, a bounding box contains the object completely. Of course, a 'perfect' bounding box would be one that coincides with the extremal points of the shape. I would not expect something like this.
BUT:
It's one thing for a bounding box to be too big and 'inefficient' but in my opinion, it is horribly wrong for the bounding box to be too small.

In my code, I generate points on the surface of the shape and then find out that they do not lie inside the bounding box?!
At least up to numeric precision (i.e., in the range of 1e-6), this should be the case. 7.3e-3 is 1000x times above this.
openBrain wrote: Sat Feb 22, 2020 9:47 am FreeCAD shapes are BREP and so BoundBox may vary depending on tessellation settings (this is especially true on curved objects).
I see. Is there a function that provides a conservative bounding box (i.e., a bounding box that might be too big but at least contains the object for sure)?
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: BoundBox too small

Post by openBrain »

Thomas_A wrote: Sun Feb 23, 2020 4:44 pm Thanks for the elaborations. I am new to FreeCAD and I now understand where the problem comes from.

I see. Is there a function that provides a conservative bounding box (i.e., a bounding box that might be too big but at least contains the object for sure)?
Not a native function AFAIK. You can expand the returned bounding box with the deviation of the object. ;)
kisolre
Veteran
Posts: 4166
Joined: Wed Nov 21, 2018 1:13 pm

Re: BoundBox too small

Post by kisolre »

Dont have where to test right now but if a PD revolved torus is created what will be the bounding box?
Post Reply