pythonocc 计算周长,面积,体积

from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Pln
from OCC.Core.GC import GC_MakeSegment
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge,BRepBuilderAPI_MakePolygon, BRepBuilderAPI_MakeFace
from OCC.Core.BRepGProp import brepgprop_LinearProperties, brepgprop_SurfaceProperties, brepgprop_VolumeProperties
from OCC.Core.GProp import GProp_GProps

from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox

 

def GetTrapezoid2dShape(x0, x1, x2, x3, z0, z1, aPlane):
    # ZOX plane
    # x0 is bottom left, x1 is bottom 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()

def GetBoxShape(box_corner, width = 1.0, height = 2.0, depth = 3.0):
    # width: 宽,dx  height:长,dy  depth:高,dz box_corner:box的左下角的点
    box = BRepPrimAPI_MakeBox(box_corner, width, height, depth).Shape()

    return box

if __name__ == '__main__':
    
    aP1 = gp_Pnt(0, 0.0, 1)
    aP2 = gp_Pnt(13, 0.0, 1)
    aSegment12 = GC_MakeSegment(aP1, aP2)
    aEdge12 = BRepBuilderAPI_MakeEdge(aSegment12.Value()).Edge()
    system = GProp_GProps()
    brepgprop_LinearProperties(aEdge12, system)
    print("aEdge12.Mass(): ", system.Mass())   # 周长
    
    p0 = gp_Pnt()
    vnorm = gp_Dir(0, 1, 0)
    aPlane = gp_Pln(p0, vnorm)
    
    aTrapezoidShape = shape2d.GetTrapezoid2dShape(-15, 15, 5, -5, 0, 10, aPlane)
    brepgprop_SurfaceProperties(aTrapezoidShape, system)
    print("aTrapezoidShape.Mass(): ", system.Mass()) # 面积

    aFilmShape = shape3d.GetBoxShape(gp_Pnt(-50, -50, 0), 100, 100, 1)
    brepgprop_VolumeProperties(aFilmShape, system)
    print("aTrapezoidShape.Mass(): ", system.Mass()) # 体积

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值