目录
1、二维几何
gp_XY定义二维坐标值
gp_Pnt2d定义二维点
gp_Dir2d描述了二维空间中的一个单位向量。
gp_Vec2d描述了二维空间中的一个向量。
2、三维几何
gp_XYZ定义三维坐标值
gp_Pnt定义三维点
gp_Dir描述了三维空间中的一个单位向量。
gp_Ax1定义旋转轴、对称轴、直线的方向等
gp_Ax2定义几何位置(几何的Position即是此坐标系的原点),如圆的位置,球体的位置。
gp_Ax3与Ax2基本一致,只是其可以定义为左旋坐标系。
3、创建直线段
4、创建圆
5、Bezier曲线
6、Bezier和直线围城曲面
7、在曲线上生成点
8、创建带孔面
9、创建圆形拉伸面
10、创建圆形拉伸面
11、在曲面上生成点
#include
#include
#include
#include"Viewer.h"
int main(int argc, char* argv[])
{
//两点创建直线
gp_Pnt P1(0., 0., 0.);
gp_Pnt P2(0., 10., 0.);
GC_MakeSegment MC(P1, P2);
Handle(Geom_TrimmedCurve) C = MC.Value();
TopoDS_Edge edge11 = BRepBuilderAPI_MakeEdge(C);
Viewer vout(50, 50, 500, 500);
vout << edge11;
vout.StartMessageLoop();
return 0;
}
#include
#include
#include
#include
#include
#include
#include"Viewer.h"
int main(int argc, char* argv[])
{
//三点创建圆弧
gp_Pnt P1(0., 0., 0.);
gp_Pnt P2(0., 10., 0.);
gp_Pnt P3(10., 0., 0.);
gce_MakeCirc MC(P1, P2, P3);
if (MC.IsDone())
{
const gp_Circ& C = MC.Value();
}
else {
gce_ErrorType type = MC.Status();
//对各种错误进行处理
}
TopoDS_Edge edge11 = BRepBuilderAPI_MakeEdge(MC);
Viewer vout(50, 50, 500, 500);
vout << edge11;
vout.StartMessageLoop();
return 0;
}
#include
#include
#include
#include"Viewer.h"
int main(int argc, char* argv[])
{
//Non Rational B-Spline
gp_Pnt points1[8] = {
gp_Pnt(0.0,-100.0,0.0),
gp_Pnt(10.0,10.0,0.0),
gp_Pnt(30.0,-100.0,0.0),
gp_Pnt(100.0,0.0,0.0),
gp_Pnt(150.0,50.0,0.0),
gp_Pnt(200.0,0.0,0.0),
gp_Pnt(400.0,200.0,0.0),
gp_Pnt(450.0,0.0,0.0)
};
NCollection_Array1 points(points1[0], 1, 8);//Control points
Standard_Real realsWeight[8] = { 1.0,1.0,1.0,1.0,1.0,1.0,10.0,1.0 };
NCollection_Array1 weight(realsWeight[0], 1, 8);//权系数,倒数第二个点的权系数是其他的10倍。
Geom_BezierCurve bezier(points); //Non-Rational
Geom_BezierCurve rationalBezier(points, weight);//Rational
Handle(Geom_BezierCurve) bezier1 = &bezier;
Handle(Geom_BezierCurve) bezier2 = &rationalBezier;
TopoDS_Edge edge11 = BRepBuilderAPI_MakeEdge(bezier1);
TopoDS_Edge edge12 = BRepBuilderAPI_MakeEdge(bezier2);
Viewer vout(50, 50, 500, 500);
vout << edge11;
vout << edge12;
vout.StartMessageLoop();
return 0;
}
#include
#include
#include
#include
#include
#include
#include
#include"Viewer.h"
int main(int argc, char* argv[])
{
gp_Pnt pointsSur1[4] =
{
gp_Pnt(0.0,0.0,0.0),
gp_Pnt(100.0,100.0,0.0),
gp_Pnt(150.0,20.0,0.0),
gp_Pnt(300.0,0.0,0.0)
};
gp_Pnt pointsSur2[4] =
{
gp_Pnt(0.0,0.0,0.0),
gp_Pnt(-20,-50.0,0.0),
gp_Pnt(20.0,-150.0,0.0),
gp_Pnt(100.0,-300.0,0.0)
};
NCollection_Array1 pointsFace1(pointsSur1[0], 1, 4);
NCollection_Array1 pointsFace2(pointsSur2[0], 1, 4);
Geom_BezierCurve bezierFace1(pointsFace1);
Geom_BezierCurve bezierFace2(pointsFace2);
Handle(Geom_BezierCurve) bezierSur1 = &bezierFace1;
Handle(Geom_BezierCurve) bezierSur2 = &bezierFace2;
TopoDS_Edge edgeSur1 = BRepBuilderAPI_MakeEdge(bezierSur1);
TopoDS_Edge edgeSur2 = BRepBuilderAPI_MakeEdge(bezierSur2);
TopoDS_Edge edgeSur3 = BRepBuilderAPI_MakeEdge(gp_Pnt(300.0, 0.0, 0.0), gp_Pnt(100.0, -300.0, 0.0));
TopoDS_Wire wireSur = BRepBuilderAPI_MakeWire(edgeSur1, edgeSur2, edgeSur3);
TopoDS_Face face = BRepBuilderAPI_MakeFace(wireSur);
Viewer vout(50, 50, 500, 500);
vout << face;
vout.StartMessageLoop();
return 0;
}
Handle(Geom_Curve) mycurve = ... ;
GeomAdaptor_Curve C (mycurve);
GCPnts_UniformDeflection myAlgo ();
Standard_Real Deflection = ... ;// 定义容差
myAlgo.Initialize (C, Deflection);
if (myAlgo.IsDone())
{
Standard_Integer nbr = myAlgo.NbPoints();//生成点的个数
Standard_Real param;
for (Standard_Integer i = 1; i <= nbr; i++)
{
param = myAlgo.Parameter (i);// 获取每个点的参数
gp_Pnt p=mycurve->Value(param); //得到点
...
}
}
Point->Curve->Edge->Wire->Face
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include"Viewer.h"
int main(int argc, char* argv[])
{
gp_Pnt p1(0.0, 0.0, 0.0);
gp_Pnt p2(100.0, 0.0, 0.0);
gp_Pnt p3(100.0, 100.0, 0.0);
gp_Pnt p4(0.0, 100.0, 0.0);
gp_Pnt center(50.0, 50.0, 0.0);
gp_Dir Z(0.0, 0.0, 1.0);
gp_Ax2 coor(center, Z);
gp_Circ circle(coor, 20.0);
Handle(Geom_TrimmedCurve) triCurve1 = GC_MakeSegment(p1, p2);
Handle(Geom_TrimmedCurve) triCurve2 = GC_MakeSegment(p2, p3);
Handle(Geom_TrimmedCurve) triCurve3 = GC_MakeSegment(p3, p4);
Handle(Geom_TrimmedCurve) triCurve4 = GC_MakeSegment(p4, p1);
Handle(Geom_Circle) triCurve5 = GC_MakeCircle(circle); //hole
//Edge,topology
TopoDS_Edge e1 = BRepBuilderAPI_MakeEdge(triCurve1);
TopoDS_Edge e2 = BRepBuilderAPI_MakeEdge(triCurve2);
TopoDS_Edge e3 = BRepBuilderAPI_MakeEdge(triCurve3);
TopoDS_Edge e4 = BRepBuilderAPI_MakeEdge(triCurve4);
TopoDS_Edge e5 = BRepBuilderAPI_MakeEdge(triCurve5);//可以直接接受一个circle
//comibe edge to wire:wire is the assembly of edges, BRepBuilderAPI_MakeWire class can build a wire from one or more edges or connect new edges to an existing wire.
TopoDS_Wire wire = BRepBuilderAPI_MakeWire(e1,e2,e3,e4);
TopoDS_Wire hole = BRepBuilderAPI_MakeWire(e5);
//create face:Use BRepBuilderAPI_MakeFace class to create a face from a surface and wires
TopoDS_Face face = BRepBuilderAPI_MakeFace(wire);
TopoDS_Face holeFace = BRepBuilderAPI_MakeFace(hole);
//Boolean Operation,face-holeFace
TopoDS_Shape shape = BRepAlgoAPI_Cut(face, holeFace);
Viewer vout(50, 50, 500, 500);
vout << shape;
vout.StartMessageLoop();
return 0;
}
#include
#include
#include
#include
#include
#include
#include"Viewer.h"
int main(int argc, char* argv[])
{
gp_Pnt center(50.0, 50.0, 0.0);
gp_Dir Z(0.0, 0.0, 1.0);
gp_Ax2 coor(center, Z);
gp_Circ circle(coor, 20.0);
Handle(Geom_Circle) triCurve5 = GC_MakeCircle(circle);
TopoDS_Edge e5 = BRepBuilderAPI_MakeEdge(triCurve5);
gp_Vec aPrismVec(0, 0, 20);
TopoDS_Shape myBody = BRepPrimAPI_MakePrism(e5, aPrismVec);//first parameter is TopoDS_Shape
Viewer vout(50, 50, 500, 500);
vout << myBody;
vout.StartMessageLoop();
return 0;
}
#include
#include
#include
#include
#include
#include
#include"Viewer.h"
int main(int argc, char* argv[])
{
gp_Ax2 cooor(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 0.0, 1.0));
gp_Hypr hyperbolaGp(cooor, 20.0, 8.0);
Handle(Geom_Hyperbola) hyperbolaGeom = GC_MakeHyperbola(hyperbolaGp);
TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge(hyperbolaGeom, 0.1, 1.0);//将双曲线的某一部分形成Edge,至于两个参数如何控制,不懂。
gp_Vec aPrismVec(10, 0, 0);
TopoDS_Shape myBody = BRepPrimAPI_MakePrism(edge1, aPrismVec);
Viewer vout(50, 50, 500, 500);
vout << myBody;
vout.StartMessageLoop();
return 0;
}
#include
#include
#include
#include
#include
#include
#include
#include"Viewer.h"
int main(int argc, char* argv[])
{
std::vector verts; //点集合
const Standard_Real pi = 3.1415926;
gp_Sphere aSpere(gp_Ax2(), 10);
TopoDS_Face aSpFace = BRepBuilderAPI_MakeFace(aSpere, 0.0, 2 * pi, -pi / 2, pi / 2);
IMeshTools_Parameters aMeshParams; //离散的准则
aMeshParams.Deflection = .01;
aMeshParams.Angle = 0.1;
aMeshParams.Relative = Standard_False;
aMeshParams.InParallel = Standard_True;
aMeshParams.MinSize = Precision::Confusion();
aMeshParams.InternalVerticesMode = Standard_True;
aMeshParams.ControlSurfaceDeflection = Standard_True;
aMeshParams.InParallel = Standard_False;
BRepMeshData_Face MeshFace(aSpFace, new NCollection_IncAllocator);
BRepMesh_SphereRangeSplitter mySplitter;
mySplitter.Reset(&MeshFace, aMeshParams);
//此处是使BRepMesh_SphereRangeSplitter获得正确的UV参数范围;
//在OCC的Mesh中,在MeshAlgo里边也调用了AddPoint()方法。
BRepAdaptor_Surface BS1(aSpFace);
Standard_Real u_1 = BS1.FirstUParameter();
Standard_Real u_2 = BS1.LastUParameter();
Standard_Real v_1 = BS1.FirstVParameter();
Standard_Real v_2 = BS1.LastVParameter();
gp_Pnt2d p0(u_1, v_1);
gp_Pnt2d p1(u_1, v_2);
gp_Pnt2d p2(u_2, v_1);
gp_Pnt2d p3(u_2, v_2);
//
mySplitter.AddPoint(p0);
mySplitter.AddPoint(p1);
mySplitter.AddPoint(p2);
mySplitter.AddPoint(p3);
mySplitter.AdjustRange();
Handle(IMeshData::ListOfPnt2d) nodes2D = mySplitter.GenerateSurfaceNodes(aMeshParams);
for (auto iter = nodes2D->begin(); iter != nodes2D->end(); iter++) {
gp_Pnt pnd3D = mySplitter.Point(*iter);
TopoDS_Vertex aVer = BRepBuilderAPI_MakeVertex(gp_Pnt((*iter).X(), (*iter).Y(), 0));
verts.push_back(aVer);
}
Viewer vout(50, 50, 500, 500);
std::vector::iterator it = verts.begin();
while (it != verts.end())
{
vout << *it;
it++;
}
vout.StartMessageLoop();
return 0;
}