Open CASCADE学习|创建多段线与圆

使用Open CASCADE Technology (OCCT)库来创建和显示一些2D几何形状。

主要过程如下:

**包含头文件:**代码首先包含了一些必要的头文件,这些头文件提供了创建和显示几何形状所需的类和函数。

**定义变量:**在main函数中,定义了一些变量来表示圆的半径、直径、螺旋部分的高度、旋转的总角度等。

**创建矩形:**使用BRepBuilderAPI_MakePolygon类来创建一个矩形。矩形的顶点坐标被添加到rectangle1中。

**创建圆:**使用Geom2d_Circle类创建两个2D圆。这些圆在XY平面上,并且中心在原点。第一个圆的半径为R,第二个圆的半径为Rr。使用BRepBuilderAPI_MakeEdge2d类将上述的两个2D圆转换为2D边(TopoDS_Edge)。

**显示形状:**创建了一个Viewer对象vout,该对象用于显示几何形状。使用vout << rectangle1;、vout << circle1;和vout << circle2;将矩形和两个圆添加到视图中。使用vout.StartMessageLoop();启动消息循环,以便用户可以与显示的形状进行交互。

cpp 复制代码
#include <AIS_Shape.hxx>
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>
#include <AIS_InteractiveContext.hxx>
#include <V3d_View.hxx>
#include "Viewer.h"
​
​
#include <TopoDS.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <Geom2d_Circle.hxx>
#include <BRepBuilderAPI_MakeEdge2d.hxx>
#include <Geom_Plane.hxx>
​
​
int main(int argc, char** argv)
{
  Standard_Real R = 4.;//outer radius
  Standard_Real D = 2 * R;//diameter
  Standard_Real Rr = 3.5;//outer radius minus body clearance
  Standard_Real b = 1.;//web thickness
  Standard_Real d = b / 2;//
  Standard_Real H = 80.;//height of the spiral part
  Standard_Real a = 3. * M_PI;//total angle of spiral rotation
  Standard_Real sigma = 118;//point angel in degrees
​
  BRepBuilderAPI_MakePolygon rectangle1;
  rectangle1.Add(gp_Pnt(d, -R, 0));
  rectangle1.Add(gp_Pnt(R, -R, 0));
  rectangle1.Add(gp_Pnt(-d, R, 0));
  rectangle1.Add(gp_Pnt(-R, R, 0));
  rectangle1.Add(gp_Pnt(d, -R, 0));
  Handle(Geom2d_Circle) c1=new Geom2d_Circle(gp_Ax22d(gp_Pnt2d(0, 0), gp_Dir2d(0,1)), R);
  TopoDS_Edge circle1 = BRepBuilderAPI_MakeEdge2d(c1);
  Handle(Geom2d_Circle) c2 = new Geom2d_Circle(gp_Ax22d(gp_Pnt2d(0, 0), gp_Dir2d(0, 1)), Rr);
  TopoDS_Edge circle2 = BRepBuilderAPI_MakeEdge2d(c2);
  Viewer vout(50, 50, 500, 500);
  vout << rectangle1;
  vout << circle1;
  vout << circle2;
  vout.StartMessageLoop();
  return 0;
​
}
​
相关推荐
非凡ghost3 分钟前
ImageConverter(图像转换编辑工具)
图像处理·人工智能·windows·学习·计算机视觉·软件需求
@zulnger4 分钟前
python 学习笔记(闭包)
笔记·python·学习
却道天凉_好个秋9 分钟前
音视频学习(八十三):视频压缩:MJPEG技术
学习·音视频·mjpeg·视频压缩
Morwit22 分钟前
Qt qml创建c++类的单例对象
开发语言·c++·qt
June`22 分钟前
IO模型全解析:从阻塞到异步(高并发的reactor模型)
linux·服务器·网络·c++
YxVoyager27 分钟前
Qt C++ :QRegularExpression 正则表达式使用详解
c++·qt·正则表达式
闻缺陷则喜何志丹29 分钟前
【回文 字符串】3677 统计二进制回文数字的数目|2223
c++·算法·字符串·力扣·回文
李余博睿(新疆)31 分钟前
c++分治算法
c++
我的xiaodoujiao32 分钟前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 39--生成 Allure测试报告
python·学习·测试工具·pytest
QiZhang | UESTC32 分钟前
学习日记day53
学习