目录
1、加法:BRepAlgoAPI_Fuse
2、减法:BRepAlgoAPI_Cut
3、交集:BRepAlgoAPI_Common
4、交线:BRepAlgoAPI_Section
#include
#include
#include"Viewer.h"
#include
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;
}
#include
#include
#include"Viewer.h"
#include
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;
}
#include
#include
#include"Viewer.h"
#include
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;
}
#include
#include
#include"Viewer.h"
#include
#include
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;
}