pythonocc 由TopoDS_Shape得到顶点的信息,由曲面得到顶点的坐标,由梯形求出梯形的顶点

# -*- coding: utf-8 -*-
"""
Created on Fri Jul 24 16:24:29 2020

@author: JC0101
"""
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakePolygon, BRepBuilderAPI_MakeFace
from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Pln
from OCC.Display.SimpleGui import init_display
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_VERTEX
from OCC.Core.TopoDS import topods
from OCC.Core.gp import gp
from OCC.Core.BRep import BRep_Tool

def GetTrapezoidShape(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()

if __name__ == '__main__':
    
    display, start_display, add_menu, add_function_to_menu = init_display()
    
    p0 = gp_Pnt()
    vnorm = gp_Dir(0, 1, 0)
    aPlane = gp_Pln(p0, vnorm)
    bcd1 = 30
    tcd1 = 20
    ht1 = 40
    x0 = -0.5 * bcd1
    x1 = 0.5 * bcd1 
    x2 = 0.5 * tcd1 
    x3 = -0.5 * tcd1 
    z0 = 0 # bottom line
    z1 = ht1 # top line
    
    aTrapezoid1Shape = GetTrapezoidShape(x0, x1, x2, x3, z0, z1, aPlane)
    
    anVertexExplorer = TopExp_Explorer(aTrapezoid1Shape, TopAbs_VERTEX)
     
    vertex = []
    while anVertexExplorer.More(): # 有更多子形状去挖掘
        anVertex = topods.Vertex(anVertexExplorer.Current()) # 当前被探索到的子形状是哪一个, topods_Vertex
        aPnt = BRep_Tool.Pnt(anVertex) # 转换成gp_Pnt
        
        vertex.append(aPnt)
        display.DisplayShape(anVertex, update = True)   
        
        anVertexExplorer.Next() # 下一个子形状
    
    pnts = []
    for v in vertex:
        coordinate = (v.X(), v.Y(), v.Z())
        if coordinate not in pnts:
            pnts.append(coordinate)
        
    print(pnts)
    
    display.FitAll()
    start_display()
    

    

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值