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

c#获得solidworks零件的 面邻接矩阵

总共找到 23 个面 邻接关系: 面 0: 1 2 3 14 面 1: 0 12 13 11 面 2: 0 7 8 13 面 3: 0 6 8 12 面 4: 5 6 7 8 面 5: 4 6 7 15 面 6: 5 4 3 17 面 7: 5 4 2 16 面 8: 4 3 2 10 面 9: 10 11 12 13 面 10: 9 12 13 8 面 11: 9 12 13 1 面 12: 9 10 11 3 1 面 13: 9 10 11 1 2 面 14: 0 16 17 20 面 15: 5 16 17 19 面 16: 14 7 15 21 面 17: 14 6 15 22 面 18: 19 20 21 22 面 19: 18 21 22 15 面 20: 18 21 22 14 面 21: 20 18 19 16 面 22: 20 18 19 17 完整邻接矩阵: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 0: 0 1 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1: 1 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 2: 1 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 3: 1 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 4: 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5: 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 6: 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 7: 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 8: 0 0 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 9: 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0: 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 1: 0 1 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 2: 0 1 0 1 0 0 0 0 0 1 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 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 4: 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 5: 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 6: 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 7: 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 4: 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 5: 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 4: 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 4: 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 5: 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 6: 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 7: 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 8: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 9: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 1 0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 1 1: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 0 0 2: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0

根据您提供的邻接矩阵结果,这是SolidWorks模型中23个面之间的邻接关系的数学表示。让我详细解释一下:

邻接矩阵含义

基本概念

  • 面的数量:您的模型共有23个面(编号0-22)
  • 邻接定义:两个面如果通过一条公共边相连,则称为相邻面

邻接关系解析

1. 第一部分:邻接列表

面 0: 1 2 3 14

表示面0面1、面2、面3、面14相邻

2. 第二部分:邻接矩阵
  • 矩阵大小:23×23
  • 数值含义:
    • 1表示两个面对应位置相邻
    • 0表示两个面不相邻
    • 矩阵是对称的(因为邻接关系是双向的)

模型拓扑特征分析

高度连接的面
  • 面12和面13:各与5个面相邻,是模型中连接最广泛的面
  • 面0:与4个面相邻,也是重要连接点
连接模式

您的模型似乎具有以下结构特点:

  1. 前部区域(面0-13):形成一个密集连接的子图
  2. 后部区域(面14-22):另一个密集连接的子图
  3. 中间连接:面4-8作为两个区域之间的桥梁

拓扑意义

这种邻接关系反映了SolidWorks模型的几何结构:

  • 面与面的共享边界决定了邻接关系
  • 复杂几何体会有更多邻接关系
  • 简单几何体(如立方体)通常有较少的邻接关系

实际应用价值

  1. 模型分析:了解几何体的拓扑结构
  2. 特征识别:帮助识别模型的重要几何特征
  3. 算法优化:为后续的几何处理算法提供基础数据
  4. 质量检查:验证模型的拓扑完整性

这实际上是一个图论中的无向图,其中每个面是节点,邻接关系是边。这种表示在计算机辅助设计(CAD)和计算机图形学中非常有用。

using System; using System.IO; using System.Runtime.InteropServices; using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using View = SolidWorks.Interop.sldworks.View; namespace tools { class get_all_edges { /// <summary> /// 获取工程图中的尺寸信息 /// </summary> static public void run() { // 连接到 SolidWorks 应用程序 SldWorks? swApp = Connect.run(); if (swApp == null) { Console.WriteLine("错误:无法连接到 SolidWorks 应用程序。"); return; } // 获取活动文档并转换为 DrawingDoc 类型 ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc; if (swModel == null) { Console.WriteLine("错误:没有打开的活动文档。"); return; } PartDoc partDoc = (PartDoc)swModel; // 获取所有实体 object[] vBodies = (object[])partDoc.GetBodies2((int)swBodyType_e.swSolidBody, false); // 存储邻接矩阵的字典:面索引 -> 相邻面集合 var adjacencyMatrix = new System.Collections.Generic.Dictionary<int, System.Collections.Generic.HashSet<int>>(); var faceIndexMap = new System.Collections.Generic.Dictionary<Face2, int>(); // 面对象到索引的映射 var facesList = new System.Collections.Generic.List<Face2>(); // 面对象列表 int faceCount = 0; foreach (Body2 body in vBodies) { object[] vedges = (object[])body.GetEdges(); foreach (Edge edge in vedges) { var twoAdjacentFaces = (object[])edge.GetTwoAdjacentFaces(); if (twoAdjacentFaces != null && twoAdjacentFaces.Length >= 2) { Face2 face1 = (Face2)twoAdjacentFaces[0]; Face2 face2 = (Face2)twoAdjacentFaces[1]; // 为每个面分配唯一索引 if (!faceIndexMap.ContainsKey(face1)) { faceIndexMap[face1] = faceCount++; facesList.Add(face1); } if (!faceIndexMap.ContainsKey(face2)) { faceIndexMap[face2] = faceCount++; facesList.Add(face2); } int index1 = faceIndexMap[face1]; int index2 = faceIndexMap[face2]; // 初始化邻接矩阵条目 if (!adjacencyMatrix.ContainsKey(index1)) adjacencyMatrix[index1] = new System.Collections.Generic.HashSet<int>(); if (!adjacencyMatrix.ContainsKey(index2)) adjacencyMatrix[index2] = new System.Collections.Generic.HashSet<int>(); // 添加邻接关系 adjacencyMatrix[index1].Add(index2); adjacencyMatrix[index2].Add(index1); } } } // 输出邻接矩阵信息 Console.WriteLine($"总共找到 {faceCount} 个面"); Console.WriteLine("邻接关系:"); for (int i = 0; i < faceCount; i++) { Console.Write($"面 {i}: "); if (adjacencyMatrix.ContainsKey(i)) { foreach (int adjacentFace in adjacencyMatrix[i]) { Console.Write($"{adjacentFace} "); } } Console.WriteLine(); } // 如果需要完整的邻接矩阵形式,可以创建二维数组 bool[,] fullAdjacencyMatrix = CreateFullAdjacencyMatrix(adjacencyMatrix, faceCount); // 打印完整的邻接矩阵 PrintAdjacencyMatrix(fullAdjacencyMatrix, faceCount); } /// <summary> /// 创建完整的邻接矩阵 /// </summary> private static bool[,] CreateFullAdjacencyMatrix( System.Collections.Generic.Dictionary<int, System.Collections.Generic.HashSet<int>> adjacencyDict, int size) { bool[,] matrix = new bool[size, size]; foreach (var kvp in adjacencyDict) { int faceIndex = kvp.Key; foreach (int adjacentFace in kvp.Value) { matrix[faceIndex, adjacentFace] = true; matrix[adjacentFace, faceIndex] = true; // 确保对称性 } } return matrix; } /// <summary> /// 打印邻接矩阵 /// </summary> private static void PrintAdjacencyMatrix(bool[,] matrix, int size) { Console.WriteLine("\n完整邻接矩阵:"); Console.Write(" "); for (int j = 0; j < size; j++) { Console.Write($"{j % 10} "); } Console.WriteLine(); for (int i = 0; i < size; i++) { Console.Write($"{i % 10}: "); for (int j = 0; j < size; j++) { Console.Write($"{(matrix[i, j] ? "1" : "0")} "); } Console.WriteLine(); } } } }

点击链接加入群聊【solidworks神经网络自动标注小白群】:https://qm.qq.com/q/RSpuwGqQYq

http://www.jsqmd.com/news/447270/

相关文章:

  • 从ImageNet到GLUE:盘点深度学习领域那些影响深远的benchmark数据集
  • 企业边缘AI基建:AI应用架构师的部署与管理实战
  • Power Query逆透视列实战:5分钟搞定Excel数据行列转换(附常见错误排查)
  • STM32F429IG驱动3.5寸ILI9486屏幕实战:从寄存器操作到汉字显示全流程
  • Glass数据库迁移终极指南:10个关键策略保障版本控制与数据一致性
  • 百度之星-第五维度
  • TinyGPSPlus库深度解析:如何用3行代码搞定STM32的NMEA数据解析
  • AntV-G6实战:5分钟搞定可交互拓扑图编辑器(附完整代码)
  • Glass Prompt工程终极指南:构建高效AI提示模板的10个技巧
  • Res-SAM实战案例:如何用AI自动生成精确的缺陷分割掩码
  • ESP32开发实战:如何高效管理IDF组件依赖(附避坑指南)
  • 蛋白互作分析避坑指南:PDB预处理 vs AlphaFold结构怎么选?
  • Kotlin/Native终极云存储指南:AWS/Azure/GCP完美集成方案
  • 解决Matplotlib中文乱码:从DejaVu Sans到SimHei的完整配置指南(附常见问题排查)
  • Glass键盘快捷键终极指南:提升工作效率的10个实用技巧
  • Kotlin/Native终极部署指南:应用商店发布与更新策略详解
  • 各种橡胶的特性介绍
  • 未来生物计算模型核心能力:提示工程架构师需掌握的提示工程创新技术
  • LangGraph实战:如何用SSE协议远程调用MCP Server(附完整代码示例)
  • 妙言MiaoYan LaTeX数学公式:科研工作者的写作利器指南
  • Python27虚拟环境离线安装pandas避坑指南:从whl文件选择到依赖解决
  • Python学习
  • uport1100系列转接头,SZ系列光电编码器RS485通信
  • Alpakka Elasticsearch集成指南:构建实时日志处理管道的5个技巧
  • 基于人工智能+AI的展会展位预订赞助信息管理系统
  • 终极Nano Stores Computed存储指南:如何构建高效响应式数据流
  • 2025 年磁力驱动泵十大品牌排行榜(排名不分先后)
  • 麒麟V10 sp3操作系统下载离线rpm包
  • 如何用Flipper Zero玩空战迷宫游戏:VGM模块使用教程
  • 解读大数据领域数据科学的地理信息系统应用