OCC创建各种体、曲线,离散曲线,点在一个平面的投影等函数使用方法

OCC代码使用

    // 在特定平面创建一个box solid
	gp_Pnt left_point;
    gp_Dir main_dir;
    gp_Dir x_dir;
    gp_Ax2 Axis(left_point, main_dir, x_dir);
    TopoDS_Solid S = BRepPrimAPI_MakeBox(Axis, dxLen, dyLen, dzLen);
    if (S.IsNull())
    {
        return false;
    }
	
	// 创建一个球
	TopoDS_Solid S = BRepPrimAPI_MakeSphere(ptCen, radius);
    
    // 创建一个圆柱
    gp_Ax2 Axis(left_point, main_dir, x_dir);
    TopoDS_Solid S = BRepPrimAPI_MakeCylinder(Axis, radius, height);
    
	 // 创建一个圆锥
    gp_Ax2 Axis(left_point, main_dir, x_dir);
    TopoDS_Solid S = BRepPrimAPI_MakeCone(Axis, bottomRadius, topRadius, height);
    
   	// 创建一个圆环
    gp_Ax2 Axis(left_point, main_dir, x_dir);
    TopoDS_Solid S = BRepPrimAPI_MakeTorus(Axis, majorRadius, minorRadius);

    // 创建一个倒角
    BRepFilletAPI_MakeChamfer chamfer(ownershape);
    chamfer.Add(leftRange, rightRange, topoEdge, topoFace);
    chamfer.Build();
    if (!chamfer.IsDone())
        return false;

    // 创建一个倒圆角
    BRepFilletAPI_MakeFillet fillet(ownershape);
    fillet.Add(radius, radius, topoEdge);
    fillet.Build();
    if (!fillet.IsDone())
        return false;

    // 投影一个点到平面上
    gp_Pnt gpPt1;
    gp_Pnt gpCenPt;
    gp_Dir gpDir;
    gp_Pln gpPln(gpCenPt, gpDir);
    gp_Pnt2d gpPnt = ProjLib::Project(gpPln, gpPt1);
    gp_Pnt gpPt2 = ElSLib::Value(gpPnt.X(), gpPnt.Y(), gpPln);
    
    // 获得 TopoDS_Edge 的长度
    GProp_GProps myProps;
    BRepGProp::LinearProperties(topoEdge, myProps);
    Standard_Real dLen = myProps.Mass();
    
    // 获得离散 TopoDS_Edge 后的点集
    BRepAdaptor_Curve acurve(topoEdge);
    GCPnts_TangentialDeflection* myMesh = new GCPnts_TangentialDeflection(acurve, angle, inMaxLength);
    if (myMesh == NULL)
    {
        return false;
    }
    int num_points = myMesh->NbPoints();
    for (int i = 1; i <= num_points; i++)
    {
        gp_Pnt gp_pnt = myMesh->Value(i);
    }
    delete myMesh;
    
    // 三点创建圆弧
    gp_Pnt pt1;
    gp_Pnt pt2;
    gp_Pnt pt3;
    Handle(Geom_TrimmedCurve) curve_ptr = GC_MakeArcOfCircle(pt1, pt3, pt2);
    BRepBuilderAPI_MakeEdge makeEdge(curve_ptr, pt1, pt3);
    TopoDS_Edge new_edge = makeEdge.Edge();

    // 三点创建圆
    gp_Pnt pt1;
    gp_Pnt pt2;
    gp_Pnt pt3;
    Handle(Geom_Circle) curve_ptr = GC_MakeCircle(pt1, pt3, pt2);
    BRepBuilderAPI_MakeEdge makeEdge(curve_ptr, pt1, pt3);
    TopoDS_Edge new_edge = makeEdge.Edge();
    
    // 删除 TopoDS_Edge
    BRepTools::RemoveUnusedPCurves(new_edge);

    // 创建圆弧
    gp_Pnt gpPt1;
    gp_Pnt gpPt2;
    gp_Pnt cen_point;
    gp_Dir main_dir;
    gp_Dir x_dir;
    gp_Ax2 Axis;
    gp_Circ gpCircle(Axis, radius);
    Handle(Geom_TrimmedCurve) curve_ptr = GC_MakeArcOfCircle(gpCircle, gpPt1, gpPt2, true);
    BRepBuilderAPI_MakeEdge makeEdge(curve_ptr, gpPt1, gpPt2);
    TopoDS_Edge new_edge = makeEdge.Edge();

    // 创建椭圆
    gp_Pnt cen_point;
    gp_Dir main_dir;
    gp_Dir x_dir;
    gp_Ax2 Axis;
    Handle(Geom_Ellipse) curve_ptr = GC_MakeEllipse(Axis, majorRad, minorRad);
    BRepBuilderAPI_MakeEdge makeEdge(curve_ptr);
    TopoDS_Edge new_edge = makeEdge.Edge();
    
    // 创建直线
    gp_Pnt gpPt1;
    gp_Pnt gpPt2;
    Handle(Geom_Line) curve_ptr = GC_MakeLine(gpPt1, gpPt2);
    BRepBuilderAPI_MakeEdge makeEdge(curve_ptr);
    TopoDS_Edge new_edge = makeEdge.Edge();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值