Open CASCADE学习|布尔运算

本文介绍了如何使用GeometricAlgebraAPI(BRepAlgoAPI)中的四个主要功能:BRepAlgoAPI_Fuse执行加法运算(融合),BRepAlgoAPI_Cut执行减法运算(切割),BRepAlgoAPI_Common执行交集运算,以及BRepAlgoAPI_Section执行交线运算。实例展示了如何在SolidWorks中使用这些函数处理几何体
摘要由CSDN通过智能技术生成

目录

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;}

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;}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值