Open CASCADE学习|自定义圆柱螺旋线

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

  • 10
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值