View Issue Details

IDProjectCategoryView StatusLast Update
0027042CommunityOCCT:Modeling Algorithmspublic2016-01-11 17:11
ReporterEpy Assigned Tobugmaster  
PrioritynormalSeverityminor 
Status closedResolutionno change required 
PlatformAll 
Product Version6.8.0 
Summary0027042: Bnd_Box fails to correctly calculate bounding box on scaled sphere
DescriptionCreating a sphere and calculating the bounding box produces the correct results, but then scaling that sphere and calculating bounding box again produces incorrect results. See the attached C++ program. The first results are as expected (10, 10, 10), but after scaling instead of getting (20, 20, 20) you get (30, 34.641, 20)
Steps To Reproduce#include <ostream>
#include <Standard_Real.hxx>
#include <TopoDS_Shape.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <Bnd_Box.hxx>
#include <BRepBndLib.hxx>
#include <gp_GTrsf.hxx>
#include <gp_Mat.hxx>
#include <BRepBuilderAPI_GTransform.hxx>

int main()
{
    Standard_Real r = 5, xmin, ymin, zmin, xmax, ymax, zmax;

    TopoDS_Shape sp = BRepPrimAPI_MakeSphere(r).Shape();

    Bnd_Box bbox;
    BRepBndLib::Add(sp, bbox);
    bbox.Get(xmin, ymin, zmin, xmax, ymax, zmax);
    std::cout << xmax - xmin << ", " << ymax - ymin << ", " << zmax - zmin << std::endl;

    gp_GTrsf scale_trsf;
    gp_Mat t(2, 0, 0, 0, 2, 0, 0, 0, 2);
    scale_trsf.SetVectorialPart(t);
    TopoDS_Shape sp2 = BRepBuilderAPI_GTransform(sp, scale_trsf).Shape();

    Bnd_Box bbox2;
    BRepBndLib::Add(sp2, bbox2);
    bbox2.Get(xmin, ymin, zmin, xmax, ymax, zmax);
    std::cout << xmax - xmin << ", " << ymax - ymin << ", " << zmax - zmin << std::endl;

    return 0;
}
TagsNo tags attached.
Test case number

Attached Files

Activities

Epy

2015-12-27 19:52

developer  

test.cxx (992 bytes)   

msv

2015-12-28 11:58

developer   ~0049627

The same result we can obtain using the following draw script:

psphere s 5
puts [bounding s]
scalexyz r s 2 2 2
puts [bounding r]

The bounding boxes are the following:

-5.0000001000000003 -5.0000001000000003 -5.0000001000000003 5.0000001000000003 5.0000001000000003 5.0000001000000003
-20.000000199999995 -17.320508275688777 -10.000000200000001 10.000000200000001 17.320508275688766 10.000000200000001

This result is as expected. It is because the algorithm BRepBuilderAPI_GTransform generates b-spline geometries, and the bounding box on b-splines is constructed using its poles. The poles of this spheric b-spline are shown in the attached picture.

In order to keep the geometry form of the original shape you need to use isotropic transformation that is done with the classes gp_Trsf and BRepBuilderAPI_Transform. For that, the piece of transforming code should look like this:

    gp_Trsf scale_trsf;
    scale_trsf.SetScale(gp::Origin(), 2);
    TopoDS_Shape sp2 = BRepBuilderAPI_Transform(sp, scale_trsf).Shape();

Or, using draw script:

tscale s 0 0 0 2

After doing this, the bounding box is the following:

-10.000000200000001 -10.000000200000001 -10.000000200000001 10.000000200000001 10.000000200000001 10.000000200000001

And the program puts:

10, 10, 10
20, 20, 20

As you expected.

Epy

2015-12-28 18:50

developer   ~0049656

Thanks, I understand now. This can be closed.

Issue History

Date Modified Username Field Change
2015-12-27 19:52 Epy New Issue
2015-12-27 19:52 Epy Assigned To => msv
2015-12-27 19:52 Epy File Added: test.cxx
2015-12-28 11:58 msv Note Added: 0049627
2015-12-28 11:59 msv Assigned To msv => Epy
2015-12-28 11:59 msv Status new => feedback
2015-12-28 18:50 Epy Note Added: 0049656
2015-12-28 19:09 msv Assigned To Epy => bugmaster
2016-01-11 17:11 bugmaster Status feedback => closed
2016-01-11 17:11 bugmaster Resolution open => no change required