PythonOCC基础使用:曲面建模

opencascade 提供了基本曲面(平面,圆柱面,锥面,球面),以及Bezier()和B-样条曲面,回转曲面,拉伸和偏移曲面,曲面裁剪后可以得到裁剪曲面(trimmed surface)啊

  • 贝塞尔曲线(Bézier curve),又称贝兹曲线或贝济埃曲线,是应用于二维图形应用程序的数学曲线。一般的矢量图形软件通过它来精确画出曲线,贝兹曲线由线段与节点组成,节点是可拖动的支点,线段像可伸缩的皮筋,我们在绘图工具上看到的钢笔工具就是来做这种矢量曲线的。
  • B-样条是贝兹曲线(又称贝塞尔曲线)的一种一般化,可以进一步推广为非均匀有理B样条(NURBS),使得我们能给更多一般的几何体建造精确的模型。

直纹曲面(ruled surface)

直纹曲面是两条曲线形成的曲面(通过直线沿着两条曲线上的点运动形成的),平面(平行直线),圆锥面(平行圆用直线连接)

  • 1.由两条曲线生成对应曲面
    在这里插入图片描述geomfill_Surface 该函数是核心函数
from OCC.Core.GeomFill import GeomFill_Pipe, geomfill_Surface
from OCC.Core.gp import gp_Pnt
from OCC.Core.BRepBuilderAPI import  BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire
from OCC.Core.TColgp import TColgp_HArray1OfPnt
from OCC.Core.GeomAPI import GeomAPI_Interpolate



# 生成第一个曲线
Linearray1 = TColgp_HArray1OfPnt(1, 5)
Linearray1.SetValue(1, gp_Pnt(5, 0, 0))
Linearray1.SetValue(2, gp_Pnt(4, 1.5, 0))
Linearray1.SetValue(3, gp_Pnt(3, 2, 0))
Linearray1.SetValue(4, gp_Pnt(2, 3, 0))
Linearray1.SetValue(5, gp_Pnt(0, 4.5, 0))
bspline_11 = GeomAPI_Interpolate(Linearray1, False, 0.00001)
bspline_11.Perform()
bspline_21 = bspline_11.Curve()
bspline_31 = BRepBuilderAPI_MakeEdge(bspline_21)
bspline1 = BRepBuilderAPI_MakeWire(bspline_31.Edge()).Wire()

# 生成第二个曲线
Linearray2 = TColgp_HArray1OfPnt(1, 5)
Linearray2.SetValue(1, gp_Pnt(8, 0, 5))
Linearray2.SetValue(2, gp_Pnt(7, 1.7, 5))
Linearray2.SetValue(3, gp_Pnt(6, 2.4, 5))
Linearray2.SetValue(4, gp_Pnt(3, 3.2, 5))
Linearray2.SetValue(5, gp_Pnt(1, 5, 5))
bspline_12 = GeomAPI_Interpolate(Linearray2, False, 0.00001)
bspline_12.Perform()
bspline_22 = bspline_12.Curve()
bspline_32 = BRepBuilderAPI_MakeEdge(bspline_22)
bspline2 = BRepBuilderAPI_MakeWire(bspline_32.Edge()).Wire()

# 二个曲线生成曲面
surface=geomfill_Surface(bspline_21,bspline_22)


if __name__ == "__main__":
    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(bspline1, update=True)
    display.DisplayShape(bspline2, update=True)
    display.DisplayShape(surface, update=True)


    start_display()

brepfill_Face() 计算两edge的直纹曲面

参数:

Edge1 (TopoDS_Edge &) –
Edge2 (TopoDS_Edge &) –

返回类型:

TopoDS_Face

brepfill_Shell()计算出两wire(环)的直纹曲面。两环必须要有相同数量的edges
参数:

Wire1 (TopoDS_Wire &) –
Wire2 (TopoDS_Wire &) –

返回类型:

TopoDS_Shell

  • 2.由相应的点生成曲面
from OCC.Core.gp import gp_Pnt
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeFace
from OCC.Core.TColgp import TColgp_Array2OfPnt
from OCC.Core.GeomAPI import GeomAPI_PointsToBSplineSurface, GeomAPI_PointsToBSpline
from OCC.Core.GeomAbs import GeomAbs_C2
from OCC.Core.ShapeAnalysis import ShapeAnalysis_Surface, shapeanalysis_GetFaceUVBounds


p1 = gp_Pnt(-15, 200, 10)
p2 = gp_Pnt(5, 204, 0)
p3 = gp_Pnt(15, 200, 0)
p4 = gp_Pnt(-15, 20, 15)
p5 = gp_Pnt(-5, 20, 0)
p6 = gp_Pnt(15, 20, 35)

array = TColgp_Array2OfPnt(1, 3, 1, 2)
array.SetValue(1, 1, p1)
array.SetValue(2, 1, p2)
array.SetValue(3, 1, p3)
array.SetValue(1, 2, p4)
array.SetValue(2, 2, p5)
array.SetValue(3, 2, p6)
bspl_surf = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2,0.001).Surface()
face = BRepBuilderAPI_MakeFace(bspl_surf, 1e-6).Face()
# umin, umax, vmin, vmax = shapeanalysis_GetFaceUVBounds(face)
# print(umin, umax, vmin, vmax)

if __name__ == "__main__":
    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(p1, update=True)
    display.DisplayShape(p2, update=True)
    display.DisplayShape(p3, update=True)
    display.DisplayShape(p4, update=True)
    display.DisplayShape(p5, update=True)
    display.DisplayShape(p6, update=True)
    display.DisplayShape(face, update=True)
    start_display()

在这里插入图片描述

扫略

from OCC.Core.GeomFill import GeomFill_Pipe
from OCC.Core.gp import gp_Pnt
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeFace, BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire
from OCC.Core.TColgp import TColgp_Array2OfPnt, TColgp_HArray1OfPnt
from OCC.Core.GeomAPI import GeomAPI_PointsToBSplineSurface, GeomAPI_PointsToBSpline, GeomAPI_Interpolate
from OCC.Core.GeomAbs import GeomAbs_C2


Linearray2 = TColgp_HArray1OfPnt(1, 5)
Linearray2.SetValue(1, gp_Pnt(8, 0, 5))
Linearray2.SetValue(2, gp_Pnt(7, 1.7, 5))
Linearray2.SetValue(3, gp_Pnt(6, 2.4, 5))
Linearray2.SetValue(4, gp_Pnt(3, 3.2, 5))
Linearray2.SetValue(5, gp_Pnt(1, 5, 5))
bspline_12 = GeomAPI_Interpolate(Linearray2, False, 0.00001)
bspline_12.Perform()
bspline_22 = bspline_12.Curve()
bspline_32 = BRepBuilderAPI_MakeEdge(bspline_22)
bspline2 = BRepBuilderAPI_MakeWire(bspline_32.Edge()).Wire()

tube=GeomFill_Pipe(bspline_22,1)
tube.Perform()

if __name__ == "__main__":
    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(tube.Surface(), update=True)

    start_display()

在这里插入图片描述


参考文献:1. https://opencascade.blogspot.com/
2. https://wenku.baidu.com/view/888c8ad3360cba1aa911da01.html

© 版权声明
THE END
喜欢就支持一下吧
点赞798 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容