当前位置: 首页 > news >正文

pythonocc hlr实例 deepwiki 显示隐藏线

直接在pythonocc页面底下问,ai再也不会import自创类名了,带着文档编码的,降维打击了

import matplotlib.pyplot as plt  
import matplotlib.patches as patches  
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeCylinder  
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut  
from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax2  
from OCC.Extend.TopologyUtils import get_sorted_hlr_edges  
from OCC.Core.BRepAdaptor import BRepAdaptor_Curve  
from OCC.Core.GCPnts import GCPnts_UniformDeflection  # 创建立方体  
box = BRepPrimAPI_MakeBox(100, 100, 100).Shape()  # 创建圆柱体作为盲孔  
cylinder_ax = gp_Ax2(gp_Pnt(50, 50, 20), gp_Dir(0, 0, 1))  
cylinder = BRepPrimAPI_MakeCylinder(cylinder_ax, 20, 60).Shape()  # 布尔运算:从立方体中减去圆柱体  
cut_op = BRepAlgoAPI_Cut(box, cylinder)  
shape_with_hole = cut_op.Shape()  def get_projection_edges(shape, direction):  """获取指定方向的投影边"""  visible_edges, hidden_edges = get_sorted_hlr_edges(  shape,   position=gp_Pnt(0, 0, 0),  direction=direction,  export_hidden_edges=True  )  return visible_edges, hidden_edges  def edge_to_2d_points(edge, deflection=0.1):  """将3D边转换为2D点列表"""  adaptor = BRepAdaptor_Curve(edge)  discretizer = GCPnts_UniformDeflection(adaptor, deflection)  points = []  for i in range(1, discretizer.NbPoints() + 1):  pnt = discretizer.Value(i)  points.append((pnt.X(), pnt.Y()))  return points  def plot_view(ax, visible_edges, hidden_edges, title):  """绘制单个视图"""  ax.set_title(title)  ax.set_aspect('equal')  # 绘制可见线(实线)  for edge in visible_edges:  points = edge_to_2d_points(edge)  if len(points) > 1:  x_coords = [p[0] for p in points]  y_coords = [p[1] for p in points]  ax.plot(x_coords, y_coords, 'b-', linewidth=1)  # 绘制隐藏线(虚线)  for edge in hidden_edges:  points = edge_to_2d_points(edge)  if len(points) > 1:  x_coords = [p[0] for p in points]  y_coords = [p[1] for p in points]  ax.plot(x_coords, y_coords, 'r--', linewidth=0.5)  # 创建三视图  
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(15, 5))  # 正视图 (前视图)  
front_visible, front_hidden = get_projection_edges(shape_with_hole, gp_Dir(0, 1, 0))  
plot_view(ax1, front_visible, front_hidden, "正视图")  # 侧视图 (右视图)  
side_visible, side_hidden = get_projection_edges(shape_with_hole, gp_Dir(1, 0, 0))  
plot_view(ax2, side_visible, side_hidden, "侧视图")  # 俯视图 (顶视图)  
top_visible, top_hidden = get_projection_edges(shape_with_hole, gp_Dir(0, 0, 1))  
plot_view(ax3, top_visible, top_hidden, "俯视图")  plt.tight_layout()  
plt.show()

相关文章:

  • 力扣刷题Day 60:全排列(46)
  • 【Prometheus+Grafana实战:搭建监控系统(含告警配置)】
  • HTTP代理的实际用处有哪些?HTTP代理强在哪里?
  • 54、C# 委托 (Delegate)
  • 专栏更新通知
  • 如何手搓一个查询天气的mcp server
  • 【全因子组及排序】2022-1-23
  • 【计算机网络】IPv6和NAT网络地址转换
  • DeepSeek R1模型已完成小版本试升级
  • jQuery和CSS3卡片列表布局特效
  • 桃黑黑反斗战
  • Spring AI 整合聊天模型之智谱AI
  • 华为OD最新机试真题-按单词下标区间翻转文章内容-OD统一考试(B卷)
  • B3694 数列离散化
  • 【人工智能】微调革命:释放大模型的无限潜能
  • 基于seal密码库的格加密算法的原理、实现与应用
  • Shell - ​​Here Document(HereDoc)
  • AI Agent工具全景解析:从Coze到RAGflow,探索智能体自动化未来!
  • 制作一款打飞机游戏61:轨迹调度
  • git提交更改
  • 微商产品展示网站源码/最有效的推广学校的方式
  • 网站的空间是/免费十八种禁用网站
  • 动画制作软件手机版/seo免费诊断
  • 网站开发毕业论文任务书/百度百科词条创建入口
  • 顶尖手机网站建设/西安seo高手
  • 微转app是用网站做的吗/杭州seo网站优化