由《OpenCASCADE BRep Format》中可知,圆柱面的参数方程为:
通过控制圆柱面的参数空间[u,v]便可以得到任意圆柱螺旋线。
本例先根据参数生成圆柱面上的点,再把点拟合成空间曲线,从而得到螺旋线。
#include <Geom_CylindricalSurface.hxx>
#include <gp_Ax3.hxx>
#include <GeomAPI_Interpolate.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <GCE2d_MakeSegment.hxx>
#include <GeomAPI_PointsToBSpline.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include"Viewer.h"
TopoDS_Shape createHelix2(const Standard_Real HelixRadius, const Standard_Real HelixAngle, const Standard_Real HelixLength)
{
Standard_Real u0 = 0.0;
Standard_Real u1 = 2 * M_PI;
Standard_Real v0 = 0.0;
Standard_Real v1 = HelixLength;
double uInter = (u1 - u0) / 1000;
double vInter = (v1 - v0)/1000;
TColgp_HArray1OfPnt Points(1, 1001);
Handle(Geom_CylindricalSurface) aCylinder = new Geom_CylindricalSurface(gp::XOY(), HelixRadius);
double u;
double v;
//生成点
for (int i = 0; i < 1001; i++) {
u = i * vInter * tan(HelixAngle) / HelixRadius;
v = i * vInter;
Points[i + 1] = aCylinder->Value(u,v);
}
//曲线拟合
//GeomAPI_Interpolate Interp(&Points, Standard_False, Precision::Confusion());
//Interp.Perform();
//Standard_Boolean isFin = Interp.IsDone();
//Handle(Geom_BSplineCurve) aBsCurve = Interp.Curve();
//TopoDS_Edge aHelixEdge = BRepBuilderAPI_MakeEdge(aBsCurve);
GeomAPI_PointsToBSpline Approx(Points);
Handle_Geom_BSplineCurve K = Approx.Curve();
TopoDS_Edge aHelixEdge = BRepBuilderAPI_MakeEdge(K);
return aHelixEdge;
}
int main(int argc, char* argv[])
{
Handle(Geom_CylindricalSurface) aCylinder = new Geom_CylindricalSurface(gp::XOY(), 6.0);
TopoDS_Shape cF = BRepBuilderAPI_MakeFace(aCylinder->Cylinder(),0,2*M_PI,0,100);
TopoDS_Shape aE = createHelix2(6.0,M_PI/4,12* M_PI);
Viewer vout(50, 50, 500, 500);
vout << cF;
vout << aE;
vout.StartMessageLoop();
return 0;
}
标签:Real,自定义,double,Standard,CASCADE,Geom,include,Open,TopoDS
From: https://blog.csdn.net/T20151470/article/details/135984007