• 第二章:Pythonocc官方demo 案例45(几何轴向曲线偏置)


    源代码:

    #!/usr/bin/env python
    
    ##Copyright 2009-2016 Jelle Feringa (jelleferinga@gmail.com)
    ##
    ##This file is part of pythonOCC.
    ##
    ##pythonOCC is free software: you can redistribute it and/or modify
    ##it under the terms of the GNU Lesser General Public License as published by
    ##the Free Software Foundation, either version 3 of the License, or
    ##(at your option) any later version.
    ##
    ##pythonOCC is distributed in the hope that it will be useful,
    ##but WITHOUT ANY WARRANTY; without even the implied warranty of
    ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    ##GNU Lesser General Public License for more details.
    ##
    ##You should have received a copy of the GNU Lesser General Public License
    ##along with pythonOCC.  If not, see .
    
    # this example was ported from: http://heekscnc.blogspot.nl/2009/09/occ-offset.html, by Dan Heeks
    
    from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_MakeOffset
    from OCC.Display.SimpleGui import init_display
    from OCC.Core.GeomAbs import GeomAbs_Arc
    from OCC.Core.gp import gp_Pnt
    from OCC.Extend.ShapeFactory import make_edge, make_vertex, make_wire, make_face
    from OCC.Extend.TopologyUtils import TopologyExplorer
    
    display, start_display, add_menu, add_function_to_menu = init_display()
    
    
    def boolean_cut(shapeToCutFrom, cuttingShape):
        from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut
        cut = BRepAlgoAPI_Cut(shapeToCutFrom, cuttingShape)
    
        shp = cut.Shape()
        return shp
    
    
    def make_face_to_contour_from():
        v1 = make_vertex(gp_Pnt(0, 0, 0))
        v2 = make_vertex(gp_Pnt(10, 0, 0))
        v3 = make_vertex(gp_Pnt(7, 10, 0))
        v4 = make_vertex(gp_Pnt(10, 20, 0))
        v5 = make_vertex(gp_Pnt(0, 20, 0))
        v6 = make_vertex(gp_Pnt(3, 10, 0))
        e1 = make_edge(v1, v2)
        e2 = make_edge(v2, v3)
        e3 = make_edge(v3, v4)
        e4 = make_edge(v4, v5)
        e5 = make_edge(v5, v6)
        e6 = make_edge(v6, v1)
        v7 = make_vertex(gp_Pnt(2, 2, 0))
        v8 = make_vertex(gp_Pnt(8, 2, 0))
        v9 = make_vertex(gp_Pnt(7, 3, 0))
        v10 = make_vertex(gp_Pnt(3, 3, 0))
        e7 = make_edge(v7, v8)
        e8 = make_edge(v8, v9)
        e9 = make_edge(v9, v10)
        e10 = make_edge(v10, v7)
        w1 = make_wire([e1, e2, e3, e4, e5, e6])
        f = make_face(w1)
        w2 = make_wire(e7, e8, e9, e10)
        f2 = make_face(w2)
        f3 = boolean_cut(f, f2)
        return f3
    
    
    def create_offsets(face, nr_of_counters, distance_between_contours):
        offset = BRepOffsetAPI_MakeOffset()
        offset.Init(GeomAbs_Arc)
    
        for wi in TopologyExplorer(face).wires():
            offset.AddWire(wi)
    
        for i in range(nr_of_counters):
            offset.Perform(-distance_between_contours * i)
            if offset.IsDone():
                yield offset.Shape()
    
    
    face = make_face_to_contour_from()
    display.DisplayShape(face)
    
    for contour in create_offsets(face, 50, 0.12):
        display.DisplayShape(contour)
    
    display.FitAll()
    start_display()
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90

    运行效果:生成轴向偏置曲线
    在这里插入图片描述

  • 相关阅读:
    iris(golang)连接mysql数据库
    Spring Boot 之 SpringSecurity、Shiro
    【Android安全】Android SELinux机制 | Android 访问控制模型
    I/O多路复用三种实现
    1 操作系统任务调度问题----来源刘H同学
    ASRT从零搭建并测试
    取消task异步任务
    OSPF状态机+SPF算法
    CAS:1207751-12-9​,Maleimide-PEG-amine,马来酰亚胺peg氨基可用于生物结合
    MongoDB副本集群搭建和基础配置
  • 原文地址:https://blog.csdn.net/loujiand/article/details/128030571