pythonocc 交,并,减

交的概念是两个东西的公共部分,而并的概念是两个东西加起来,减的概念是从A中减去B,用集合的语言就是,交就是A\bigcap B,并就是A\bigcup B,减就是A-B。在Pythonocc里,交,并,减相对应的是common,fuse和cut,下面附上代码。

from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut, BRepAlgoAPI_Fuse, BRepAlgoAPI_Common

from OCC.Display.SimpleGui import init_display

def GetRectShape(x0, x1, z0, z1, aPlane):
    # ZOX plane
    # width is from x0 to x1, and height is from z0 to z1.
    aP1 = gp_Pnt(x0, 0.0, z0)
    aP2 = gp_Pnt(x1, 0.0, z0)
    aP3 = gp_Pnt(x1, 0.0, z1)
    aP4 = gp_Pnt(x0, 0.0, z1)
    aPolygon = BRepBuilderAPI_MakePolygon(aP1, aP2, aP3, aP4, True)
    return BRepBuilderAPI_MakeFace(aPlane, aPolygon.Wire()).Shape()

def GetTrapezoidShape(x0, x1, x2, x3, z0, z1, aPlane):
    # ZOX plane
    # x0 is bottom left, x1 is bottom is right, x2 is top right, x3 is top left
    # z0 is bottom, z1 is top
    aP1 = gp_Pnt(x0, 0.0, z0)
    aP2 = gp_Pnt(x1, 0.0, z0)
    aP3 = gp_Pnt(x2, 0.0, z1)
    aP4 = gp_Pnt(x3, 0.0, z1)
    aPolygon = BRepBuilderAPI_MakePolygon(aP1, aP2, aP3, aP4, True)
    return BRepBuilderAPI_MakeFace(aPlane, aPolygon.Wire()).Shape()

# ZOX平面

p0 = gp_Pnt()
vnorm = gp_Dir(0, 1, 0)
aPlane = gp_Pln(p0, vnorm)

x0 = -0.5 * 100
x1 = 0.5 * 100
z0 = 0
z1 = 10

aRect = GetRectShape(x0, x1, z0, z1, aPlane)

x2 = 0.5 * 50

x3 = -0.5 * 50

z1 = 5

aPolygon = GetTrapezoidShape(x0, x1, x2, x3, z0, z1, aPlane)

Jiao = BRepAlgoAPI_Common(aRect, aPolygon).Shape()  # A\bigcap B

Bing = BRepAlgoAPI_Fuse(aRect, aPolygon).Shape()  # A\bigcup B

Jian = BRepAlgoAPI_Cut(aRect, aPolygon).Shape()  # aRect- aPolygon

display, start_display, add_menu, add_function_to_menu = init_display()

display.DisplayShape(Jiao , update=True)
display.FitAll()
start_display() 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值