PythonOCC基础使用:建模——二维草图wire offeset

from OCC.Core.gp import gp_Pnt, gp_Ax2, gp_DX, gp_Circ, gp_Elips
from OCC.Core.GC import GC_MakeSegment, GC_MakeCircle, GC_MakeArcOfCircle, GC_MakeEllipse
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire, BRepBuilderAPI_MakeFace
from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_MakeOffset
from OCC.Display.SimpleGui import init_display
from OCC.Display.OCCViewer import rgb_color

# 在yz平面上通过一顶点及长宽绘制矩形
def create_rounded_rectangle(coor0, Length, Width, radius):
    yPlus = [0, Length, 0]
    zPlus = [0, 0, Width]
    coor1 = [coor0[i] + yPlus[i] for i in range(3)]
    coor2 = [coor0[i] + zPlus[i] + yPlus[i] for i in range(3)]
    coor3 = [coor0[i] + zPlus[i] for i in range(3)]
    P0 = gp_Pnt(coor0[0], coor0[1], coor0[2])
    P1 = gp_Pnt(coor1[0], coor1[1], coor1[2])
    P2 = gp_Pnt(coor2[0], coor2[1], coor2[2])
    P3 = gp_Pnt(coor3[0], coor3[1], coor3[2])

    aSegment1 = GC_MakeSegment(P0, P1)
    anEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
    aWire1 = BRepBuilderAPI_MakeWire(anEdge1.Edge())

    aSegment2 = GC_MakeSegment(P1, P2)
    anEdge2 = BRepBuilderAPI_MakeEdge(aSegment2.Value())
    aWire2 = BRepBuilderAPI_MakeWire(anEdge2.Edge())

    aSegment3 = GC_MakeSegment(P2, P3)
    anEdge3 = BRepBuilderAPI_MakeEdge(aSegment3.Value())
    aWire3 = BRepBuilderAPI_MakeWire(anEdge3.Edge())

    aSegment4 = GC_MakeSegment(P3, P0)
    anEdge4 = BRepBuilderAPI_MakeEdge(aSegment4.Value())
    aWire4 = BRepBuilderAPI_MakeWire(anEdge4.Edge())

    aRectangle = BRepBuilderAPI_MakeWire(aWire1.Edge(), aWire2.Edge(), aWire3.Edge(), aWire4.Edge())

    if radius > 0:
        fillet = BRepOffsetAPI_MakeOffset(aRectangle.Wire())
        fillet.Perform(radius)
        aRectangle = fillet.Shape()

    return aRectangle


if __name__ == "__main__":
    display, start_display, add_menu, add_function_to_menu = init_display()

    coor0 = [0, 3, 3]
    Length = 20
    Width = 10
    radius = 2

    aRectangle = create_rounded_rectangle(coor0, Length, Width, radius)

    #增加offset,>0为向外 offest,<0为向内offeset
    offset_distance1 = 1
    offset_tool1 = BRepOffsetAPI_MakeOffset()
    offset_tool1.AddWire(aRectangle)
    offset_tool1.Perform(offset_distance1)
    offset_shape1 = offset_tool1.Shape()

    offset_distance2 = 2
    offset_tool2 = BRepOffsetAPI_MakeOffset()
    offset_tool2.AddWire(aRectangle)
    offset_tool2.Perform(offset_distance2)
    offset_shape2 = offset_tool2.Shape()

    offset_distance3 = -1
    offset_tool3 = BRepOffsetAPI_MakeOffset()
    offset_tool3.AddWire(aRectangle)
    offset_tool3.Perform(offset_distance3)
    offset_shape3 = offset_tool3.Shape()

    display.DisplayShape(aRectangle, update=True)
    display.DisplayShape(offset_shape1, update=True, color=rgb_color(0, 0, 1))  # 偏移后的草图蓝色
    display.DisplayShape(offset_shape2, update=True, color=rgb_color(0, 0, 1))  # 偏移后的草图蓝色
    display.DisplayShape(offset_shape3, update=True, color=rgb_color(0, 0, 1))  # 偏移后的草图蓝色

    start_display()


在这里插入图片描述

关联:判定wire 是offset关系

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值