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;
​
}
​
相关推荐
LuminousCPP1 小时前
数据结构 - 线性表第四篇:C 语言通讯录优化升级全记录(踩坑 + 思考)
c语言·开发语言·数据结构·经验分享·笔记·学习
魔法阵维护师1 小时前
从零开发游戏需要学习的c#模块,第十四章(保存和加载)
学习·游戏·c#
张小姐的猫1 小时前
【Linux】多线程 —— 线程互斥
linux·运维·服务器·c++
_李小白2 小时前
【android opencv学习笔记】Day 17: 目标追踪(MeanShift)
android·opencv·学习
一只机电自动化菜鸟2 小时前
一建机电备考笔记(40) 建筑机电施工—排水管道施工(含考频+题型)
经验分享·笔记·学习·职场和发展·课程设计
2301_818730562 小时前
numpy的学习(笔记)
学习·numpy
GHL2842710903 小时前
Logon failed, use ctrl+c to cancel basic credential prompt
学习·prompt
共享家95273 小时前
Langchain的学习(二)
学习·langchain
victory04313 小时前
agent 学习路径解析 学习资源分享
学习
做人求其滴4 小时前
面试经典 150 题 380 274
c++·算法·面试·职场和发展·力扣