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

The position of the center coordinates that can be obtained by wire and face is different

Keito Okajima's picture
Forums: 

Hello,
I am using OpenCascade V7.4.0 on 32bit windows.

I created a wire consisting of a straight line and an ellipse, converted the wire to a face, and used it in my application.
I calculated the center coordinates of the face from the converted face, but it didn't work.
When I calculated the value from the wire before conversion, I found that the value that can be obtained changes before and after conversion.
Why does changing wire to face change the value that can be obtained when surrounded by a boundy box?
Also, how can I find the correct center point coordinate value from face?

Please use the attached Brep file to reproduce the phenomenon.
Below is a sample code that causes the symptom in my environment.

-----------------------------------------------------
    TopoDS_Wire wire;
    BRep_Builder builder;
    BRepTools::Read( wire, "BREP_FILE_PATH", builder );
    Bnd_Box bb_wire;
    BRepBndLib::Add( wire, bb_wire );
    bb_wire.SetGap( 0.0 );
    gp_Pnt wirePntCenter( ( bb_wire.CornerMax().X() + bb_wire.CornerMin().X() ) / 2.0,
                          ( bb_wire.CornerMax().Y() + bb_wire.CornerMin().Y() ) / 2.0,
                          ( bb_wire.CornerMax().Z() + bb_wire.CornerMin().Z() ) / 2.0 );

    // face
    BRepBuilderAPI_MakeFace makerFace( wire );
    TopoDS_Face face = makerFace.Face();
    Bnd_Box bb_face;
    BRepBndLib::Add( face, bb_face );
    bb_face.SetGap( 0.0 );
    gp_Pnt facePntCenter( ( bb_face.CornerMax().X() + bb_face.CornerMin().X() ) / 2.0,
                          ( bb_face.CornerMax().Y() + bb_face.CornerMin().Y() ) / 2.0,
                          ( bb_face.CornerMax().Z() + bb_face.CornerMin().Z() ) / 2.0 );

-------------------------------------------------------------------

Best regards.

Keito

Attachments: 
Kirill Gavrilov's picture

Bounding Box is not a good way to find precise shape's center.
Axis-Aligned Bounding Boxes (AABB) normally serve as optimization structures for fast but inexact in/out/overlap checks.
For this reason, computation of AABB is optimized to be as fast as possible and sacrifycing some precision - so that AABB returned by BRepBndLib is greater or equal to the most tight AABB
(though you may tweak some BRepBndLib parameters to change behavior - like using theIsOptimal=true parameter of  BRepBndLib::AddOBB() method).
Another reason for a difference is that BRepBndLib adds shape tolerances.

Consider using BRepGProp_Vinert instead of AABB for computing center of mass BRepGProp_Vinert::CentreOfMass().

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.