Formen mit OCCUtils für OpenCascade zuschneiden (boolesche Differenz)
English
Deutsch
Die OCCUtils-Bibliothek bietet eine einfache Möglichkeit, die Differenz zu berechnen oder eine Form aus der anderen auszuschneiden, in OpenCASCADE. Siehe auch Wie man einen Box-TopoDS_Solid in OpenCASCADE erstellt und Wie man einen Zylinder-TopoDS_Solid in OpenCASCADE erstellt für weitere Details zur Erstellung dieser Formen mit OCCUtils.
Bei zwei Formen:
occutils_boolean_difference.cpp
#include <occutils/Primitive.hxx>
// ...
TopoDS_Solid box = Primitive::MakeBox(10, 10, 10 /* mm */);
TopoDS_Solid cylinder = Primitive::MakeCylinder(3 /* mm diameter */,
100 /* mm length */, Primitive::Orientation::Y);kann Boolean::Cut aus OCCUtils verwendet werden, um die boolesche Differenz zu berechnen:
occutils_boolean_cut_example.cpp
TopoDS_Shape result = Boolean::Cut(box, cylinder);Vollständiges main.cpp-Beispiel mit STEP-Export:
occutils_main.cpp
#include <occutils/Primitive.hxx>
#include <occutils/STEPExport.hxx>
#include <occutils/Boolean.hxx>
using namespace OCCUtils;
int main() {
// Make basic box
TopoDS_Solid box = Primitive::MakeBox(10, 10, 10 /* mm */);
TopoDS_Solid cylinder = Primitive::MakeCylinder(3 /* mm diameter */,
100 /* mm length */, Primitive::Orientation::Y);
TopoDS_Shape result = Boolean::Cut(box, cylinder);
STEP::ExportSTEP(result, "out.step");
}Das Ergebnis (out.step) sieht in FreeCAD so aus:

Check out similar posts by category:
C/C++, OpenCASCADE
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow