Open CASCADE学习|分割曲线

文章详细描述了在C++中如何通过参数进行曲线分割,使用`GCPnts_UniformAbscissa`类实现均匀参数采样,以及创建顶点和几何对象的过程。首先演示了通过`D0`和`D1`获取点坐标,随后展示了直接对曲线进行分割以获取等间距样本点的方法。
摘要由CSDN通过智能技术生成

1、通过参数进行分割

分别获得曲线的 FirstParameter 和 LastParameter ,然后对参数进行分割,获得n个ui,并对每个ui调用D0(获得这个点的坐标值)或D1(获得这个点的坐标值和切向量)。这个方法的优点是,简单易行,好操作,缺点均分参数轴获得的曲线的分割可能不是均匀的。

#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 <GC_MakeCircle.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
​
#include <gp_GTrsf.hxx>
#include <BRepBuilderAPI_Transform.hxx>
​
#include"Viewer.h"
​
​
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_GTransform.hxx>
​
​
int main(int argc, char* argv[])
{
    gp_Dir  Z(0.0, 0.0, 1.0);
    gp_Pnt center(0, 0, 0.0);
    gp_Pnt xr(0.5, 0, 0.0);
    gp_Pnt yr(0.0, 1.0, 0.0);
    gp_Pnt zr(0.0, 0.0, 7.0);
    gp_Ax2  wb(center, Z);
    gp_Circ  wbcircle(wb, 0.125 / 2);
    TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);
    TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);
    TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);
    TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);
    gp_Pnt p1(-5, 0, 0.0);
    gp_Pnt p2(5, 0, 0.0);
    gp_Ax2  sr(center, Z);
    gp_Circ  bcircle(sr, 5);
    Handle(Geom_TrimmedCurve) bc = GC_MakeArcOfCircle(bcircle, p1, p2, 0);
    TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(bc);
    Standard_Integer splitN = 10;
    Standard_Real firstParam = bc->FirstParameter();
    Standard_Real lastParam = bc->LastParameter();
    Viewer vout(50, 50, 500, 500);
    for (Standard_Integer i = 0; i < splitN + 1; ++i)
    {
        Standard_Real ui = i * (lastParam - firstParam) / splitN;
        gp_Pnt pi;
        gp_Vec veci;
        bc->D1(ui, pi, veci);
        TopoDS_Vertex verti = BRepBuilderAPI_MakeVertex(pi);
        vout << verti;
    }
    vout << anEdge;
    vout << xline;
    vout << yline;
    vout << zline;
    vout.StartMessageLoop();
    return 0;
}
​

2、直接对曲线分割

通过类 GCPnts_UniformAbscissa 实现对一个Geom_Curve对象的平均分割,获得分割点的坐标及对应的参数,将坐标和参数存入一个列表中,供其他操作使用。

#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 <GC_MakeCircle.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
​
#include <gp_GTrsf.hxx>
#include <BRepBuilderAPI_Transform.hxx>
​
#include"Viewer.h"
​
​
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <GCPnts_UniformAbscissa.hxx>
​
​
int main(int argc, char* argv[])
{
    gp_Dir  Z(0.0, 0.0, 1.0);
    gp_Pnt center(0, 0, 0.0);
    gp_Pnt xr(0.5, 0, 0.0);
    gp_Pnt yr(0.0, 1.0, 0.0);
    gp_Pnt zr(0.0, 0.0, 7.0);
    gp_Ax2  wb(center, Z);
    gp_Circ  wbcircle(wb, 0.125 / 2);
    TopoDS_Edge wbe = BRepBuilderAPI_MakeEdge(wbcircle);
    TopoDS_Edge xline = BRepBuilderAPI_MakeEdge(center, xr);
    TopoDS_Edge yline = BRepBuilderAPI_MakeEdge(center, yr);
    TopoDS_Edge zline = BRepBuilderAPI_MakeEdge(center, zr);
    gp_Pnt p1(-5, 0, 0.0);
    gp_Pnt p2(5, 0, 0.0);
    gp_Ax2  sr(center, Z);
    gp_Circ  bcircle(sr, 5);
    Handle(Geom_TrimmedCurve) bc = GC_MakeArcOfCircle(bcircle, p1, p2, 0);
    TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(bc);
    Standard_Integer splitN = 10;
    GeomAdaptor_Curve GAC(bc);
    GCPnts_UniformAbscissa UA(GAC, splitN + 1);
    gp_Pnt* pnts = new gp_Pnt[splitN + 1];
    Standard_Real* params = new Standard_Real[splitN + 1];
    Viewer vout(50, 50, 500, 500);
    if (UA.IsDone())
    {
        Standard_Real n = UA.NbPoints();
        Standard_Integer index = 0;
        for (; index < n + 1; index++)
        {
            Standard_Real parami = UA.Parameter(index + 1);
            params[index] = parami;
            gp_Pnt tpnt;
            bc->D0(parami, tpnt);
            pnts[index] = tpnt;
            TopoDS_Vertex verti = BRepBuilderAPI_MakeVertex(tpnt);
            vout << verti;
        }
    }
    vout << anEdge;
    vout << xline;
    vout << yline;
    vout << zline;
    vout.StartMessageLoop();
    return 0;
}
​

  • 11
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Open Cascade is a powerful open-source framework for 3D modeling and CAD/CAM/CAE applications. It provides a wide range of functionality for geometric modeling, visualization, and data exchange. However, Open Cascade does not have direct support for Python. If you want to use Open Cascade with Python, you can utilize the PyOCCT library. PyOCCT is a Python binding for Open Cascade, which allows you to access and utilize Open Cascade functionality through Python scripts. To get started with Open Cascade and Python, you need to follow these steps: 1. Install Open Cascade: Download and install the Open Cascade libraries from the official website (www.opencascade.com). Make sure to choose the appropriate version for your operating system. 2. Install PyOCCT: Once Open Cascade is installed, you can install the PyOCCT library using pip. Run the following command in your terminal: ``` pip install pythonocc-core ``` 3. Start coding: Now you can import the `occt` module in your Python script and start utilizing Open Cascade's functionality. Here's a simple example to create a box: ```python from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.Display.SimpleGui import init_display box = BRepPrimAPI_MakeBox(10, 10, 10).Shape() display, start_display, add_menu, add_function_to_menu = init_display() display.DisplayShape(box) start_display() ``` This is just a basic example to get you started. Open Cascade provides a vast set of features, including advanced 3D modeling operations, meshing algorithms, and more. You can refer to the official Open Cascade documentation and PyOCCT's GitHub repository for more information and examples. Note: It's important to mention that PyOCCT is a separate project developed by the community and not officially maintained by the Open Cascade company.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值