目录
1、加法:BRepAlgoAPI_Fuse
2、减法:BRepAlgoAPI_Cut
3、交集:BRepAlgoAPI_Common
4、交线:BRepAlgoAPI_Section
1、加法:BRepAlgoAPI_Fuse
#include <gp_Pnt.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include"Viewer.h"
#include <BRepAlgoAPI_Fuse.hxx>
int main(int argc, char* argv[])
{
//第一个基本矩形
gp_Pnt P(-5, 5, -5);
TopoDS_Shape theBox1 = BRepPrimAPI_MakeBox(60, 200, 70).Shape();
//第二个基本矩形
TopoDS_Shape theBox2 = BRepPrimAPI_MakeBox(P, 20, 150, 110).Shape();
//进行布尔Union运算,将两个图形合并
TopoDS_Shape FusedShape = BRepAlgoAPI_Fuse(theBox1, theBox2);
Viewer vout(50, 50, 500, 500);
vout << theBox1;
vout << theBox2;
vout << FusedShape;
vout.StartMessageLoop();
return 0;
}
2、减法:BRepAlgoAPI_Cut
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include"Viewer.h"
#include <BRepAlgoAPI_Cut.hxx>
int main(int argc, char* argv[])
{
//基本矩形
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200, 60, 60).Shape();
//基本球体
TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape();
//基本矩形与基本球体进行几何差运算,形成新的形状
TopoDS_Shape ShapeCut = BRepAlgoAPI_Cut(theSphere, theBox);
Viewer vout(50, 50, 500, 500);
vout << ShapeCut;
vout.StartMessageLoop();
return 0;
}
3、交集:BRepAlgoAPI_Common
#include <BRepPrimAPI_MakeWedge.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include"Viewer.h"
#include <BRepAlgoAPI_Common.hxx>
int main(int argc, char* argv[])
{
//基本矩形
gp_Ax2 axe(gp_Pnt(10, 10, 10), gp_Dir(1, 2, 1));
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(axe, 60, 80, 100).Shape();
//基本楔型
TopoDS_Shape theWedge = BRepPrimAPI_MakeWedge(60., 100., 80., 20.).Shape();
//基本矩形与基本楔型进行布尔交(Intersection)运算
TopoDS_Shape theCommonSurface = BRepAlgoAPI_Common(theBox, theWedge);
Viewer vout(50, 50, 500, 500);
vout << theCommonSurface;
vout.StartMessageLoop();
return 0;
}
文章来源:https://www.toymoban.com/news/detail-826135.html
4、交线:BRepAlgoAPI_Section
#include <gp_Pln.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include"Viewer.h"
#include <BRepAlgoAPI_Section.hxx>
#include <TopoDS_Face.hxx>
int main(int argc, char* argv[])
{
gp_Dir Z(0.0, 0.0, 1.0);
gp_Dir X(1.0, 0.0, 0.0);
gp_Pnt center(0, 0, 0.0);
gp_Pln TPlane1(center, Z);
TopoDS_Face F1 = BRepBuilderAPI_MakeFace(TPlane1, -1, 1.0, -1, 1);
gp_Pln TPlane2(center, X);
TopoDS_Face F2 = BRepBuilderAPI_MakeFace(TPlane2, -1, 1.0, -1, 1);
// 进行布尔运算
BRepAlgoAPI_Section section(F1, F2, Standard_False);
section.ComputePCurveOn1(Standard_True);
section.Approximation(Standard_False);
section.Build();
Viewer vout(50, 50, 500, 500);
vout << section.Shape();
vout << F1;
vout.StartMessageLoop();
return 0;
}
文章来源地址https://www.toymoban.com/news/detail-826135.html
到了这里,关于Open CASCADE学习|布尔运算的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!