0

我正在尝试使用 PythonOCC 读取 IGES 或 STEP 格式的线框数据(请参阅此链接),以最终用于构建 FE 梁单元模型。

在 PythonOCC 中,我实际上可以在哪里提取有关边缘和曲线的属性?我已经构建了这个示例,可以打印出文件中的所有顶点:

from OCC.Extend.DataExchange import read_iges_file
from OCC.Core.TopExp import (TopExp_Explorer,
                        topexp_MapShapesAndAncestors,
                        topexp_FirstVertex,
                        topexp_LastVertex)
from OCC.Core.TopAbs import *
from OCC.Core.TopoDS import TopoDS_Shape, topods
from OCC.Core.BRep import BRep_Tool, BRep_Tool_Pnt, BRep_Tool_IsGeometric, BRep_Tool_Parameter, BRep_Tool_Curve
from OCC.Core.BRepAdaptor import BRepAdaptor_Curve
from OCC.Core.GeomTools import GeomTools_CurveSet

shape = read_iges_file('tubes.iges')

topExp = TopExp_Explorer()
topExp.Init(shape, TopAbs_EDGE)

def print_vertex(va):
    print(BRep_Tool().Pnt(va).Coord(1), BRep_Tool().Pnt(va).Coord(2), BRep_Tool().Pnt(va).Coord(3))

while topExp.More():
    edge = topExp.Current()
    first, last = topexp_FirstVertex(edge), topexp_LastVertex(edge)
    curv = BRepAdaptor_Curve(edge).Curve()
    print_vertex(first)
    print_vertex(last)
    
    topExp.Next()
    print()

也就是说,我真正想知道曲线是直线还是弧,如果是弧,中心点和半径是多少。

4

1 回答 1

0

我正在尝试做类似的事情。如果这有用,我将使用以下代码段来获取曲线的类型,然后提取顶点:

    # given and Edge edge
    curv = BRepAdaptor_Curve(edge).Curve()
    a = 0.0
    b = 0.0
    [curve_handle, a, b] = OCC.BRep.BRep_Tool.Curve(edge)
    print(curve_handle.GetObject().DynamicType().GetObject().Name())
    initial_point = OCC.gp.gp_Pnt()
    final_point = OCC.gp.gp_Pnt()
    
    curve_handle.GetObject().D0(a, initial_point)
    curve_handle.GetObject().D0(b, final_point)
    
    print(f'init: ({initial_point.X()}, {initial_point.Y()}), end ({final_point.X()}, {final_point.Y()})')
于 2021-11-18T14:46:21.773 回答