For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings


Need to speed up your development?
Have a look at our:

Samples & Tools


Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Bounding box of a cylinder

Tiberiu Chelcea's picture

I've ran into this very strange problem when trying to get the bounding box of a cylinder. For a design, I was trying to create a very flat cylinder, of radius 52 and height 5. When getting the bounding box of the cylinder, the x/y dimensions were reported as 112.568 instead of 104 (basically, there seems to be an extra space of 4.284 on each side of the cylinder on the x/y axis). When writing the design into a brep file and opening it some other place, the cylinder is displayed correctly having a diameter of 104.

Here's the code:

double radius = 52;
double height = 5;
BRepPrimAPI_MakeCylinder mkcy(radius, height);
TopoDS_Solid _solid = mkcy.Solid();

Bnd_Box boundingBox;
BRepBndLib::Add(_solid, boundingBox);

double xmin, xmax, ymin, ymax, zmin, zmax;
boundingBox.Get(xmin,ymin,zmin, xmax,ymax,zmax);
// print them.

I'm using Opencascade 6.3. Does anyone have an idea about what's going wrong here? I'm using the bounding box of these solids to do some further computations on the shape of the system, and an incorrect one creates some big problems down the line.


Tiberiu Chelcea's picture

I get the same error when using Draw:

> pload MODELING
> pcylinder cyl 52 5
> bounding cyl
-56.28439451520449 -56.28439451520449 -9.9999999999999995e-008 56.28439451520449 56.284394
51520449 5.0000001000000003

I can live with a tolerance of 1e-8 (besides, I can set it to zero using Bnd_Box::Gap), but an error of 8.568 is way too much.

Cauchy Ding's picture

Hi Tiberiu,

That's an old problem. When the shape is not tessellated, the bounding box of the shape is large than your expectation. You can read the code void BRepBndLib::Add(const TopoDS_Shape& S, Bnd_Box& B)in brepbndlib.cxx. The best method is to tessellate your shape firstly.


Tiberiu Chelcea's picture

Hi Ding,

thank you for your reply. Can you give me a pointer on how to go about tesselating my shape first? I'm pretty new to all this 3D modeling, so don't even know where to start looking.


Cauchy Ding's picture

Hi Tiberiu,

You can call API BRepMesh_IncrementalMesh Inc(shape, deflection); the deflection is the tolerance of tessellation. Following pseudocode is for your reference,
Standard_Real aDeflection = 0.001, deflection;
Bnd_Box box;
BRepBndLib::Add(shape, box);
box.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
deflection= MAX3_( aXmax-aXmin , aYmax-aYmin , aZmax-aZmin)*aDeflection;
BRepMesh_IncrementalMesh Inc(shape, deflection);


Darya Tsareva's picture

Hello, Cauchy Ding! 

Could you explain why you suggest calculating the deflection this way? 

deflection= MAX3_( aXmax-aXmin , aYmax-aYmin , aZmax-aZmin)*aDeflection; 


Tiberiu Chelcea's picture

Ding, Roman,

Thanks for the pointers -- it worked, and the limits of the bounding box are pretty close to what I knew were depending on the deflection. However, as discussed in that blog entry, there's a tradeoff between speed and accuracy -- which, in my case, it's not quite pleasant (it takes a very long time to perform the tesselation such that the bbox is accurate enough for my computations, because the deflection has to be set very low). I'll have to see how to get around this.


Roman Lygin's picture

Looks like this issue -

Hope this helps.

Tiberiu Chelcea's picture

Here's an experiment I've done on my data structures that might be helpful. My most common bounding box operation was to get the bounding box for a compound of solids. I've tried two things: (a) perform tesselation on the entire compound and get the bounding box of the entire compound and (b) perform tesselation on each individual solid and add each individual solid to a bounding box. Case (a) was about 4 times slower than case (b) -- which is good for me since it might address my issues with performance: there's still be a performance penalty hit, but less than before.