简体   繁体   English

在2D网格中查找节点/顶点的邻居

[英]Finding the neighbors of a node/vertex in a 2D mesh

I have a 2D mesh defined by nodes and elements. 我有一个由节点和元素定义的2D网格。

Structure of a node: Node ID, X position, Y position 节点的结构:节点ID,X位置,Y位置

Structure of an element: Element ID, Node 1, Node 2, Node 3, Node 4 元素的结构:元素ID,节点1,节点2,节点3,节点4

Example of a 2x2 elements mesh: 2x2元素网格的示例:

Nodes:

 ID  X  Y
  1  0  0
  2  0  1
  3  0  2
  4  1  0
  5  1  1
  6  1  2
  7  2  0
  8  2  1
  9  2  2

Elements:

 ID N1 N2 N3 N4
  1  1  2  4  5
  2  2  3  5  6  
  3  4  5  7  8
  4  5  6  8  9

N7-----N8-----N9
|      |      |
|  E3  |  E4  |
|      |      |
N4-----N5-----N6
|      |      |
|  E1  |  E2  |
|      |      |
N1-----N2-----N3

I'm storing both nodes and elements in linked lists. 我将节点和元素都存储在链接列表中。

My question: How can I find the neighbors (nodes) for an arbitrary selected node? 我的问题: 如何找到任意选定节点的邻居(节点)?

The neighbors of N5, for example, would be N2, N4, N6 and N8. 例如,N5的邻居将是N2,N4,N6和N8。

*Note: This 2x2 element mesh simplified example for explanation proposes, the meshes I'm dealing with may contain several thousands of nodes and elements. *注意:这个2x2元素网格简化示例用于说明,我正在处理的网格可能包含数千个节点和元素。 I also have been looking at some concepts of graph theory, but I'm not sure which may be the right way to go. 我也一直在研究图论的一些概念,但是我不确定哪个可能是正确的方法。

It would be good to have element's vertices ordered in a way that they make closed polygon. 最好使元素的顶点排序为闭合多边形。 Vertices [1, 2, 4, 5] do not uniquely define first element. 顶点[1、2、4、5]不会唯一地定义第一个元素。 From your description it can be seen that you mean that is a polygon with four vertices in order (1, 2, 5, 4). 从您的描述中可以看出,您的意思是这是一个依次具有四个顶点(1、2、5、4)的多边形。 But without picture it can be also degenerated quad (1, 2, 4, 5). 但是,如果没有图片,它也可以退化为四边形(1、2、4、5)。

Like: 喜欢:

Elements:

 ID N1 N2 N3 N4
  1  1  2  5  4
  2  2  3  6  5
  3  4  5  8  7
  4  5  6  9  8

If you are not sure about vertices order, than you have to check about element self-intersection, and reorder vertices to resolve intersections. 如果不确定顶点顺序,则必须检查元素自相交,然后对顶点重新排序以解决相交。

With that kind of data it is easy to find all neighbours of given node. 利用这种数据,很容易找到给定节点的所有邻居。 Pass through all elements, if element contains given node, than there are two neighbours in that element, vertex before and after in a list. 遍历所有元素(如果元素包含给定的节点),则该元素中有两个邻居,即列表中之前和之后的顶点。

For node 5, in first element there are neighbours 2 and 4, in second element there are neighbours 6 and 2, ... 对于节点5,在第一个元素中有邻居2和4,在第二个元素中有邻居6和2,...

If there will be lot of inquires of this kind, than it is better to make extract connectivity information in separate structure. 如果会有大量此类查询,则最好以单独的结构提取连接信息。 That can be map that maps node to set of it's neighbours. 可以是将节点映射到邻居集合的映射。 To make it, pass through all elements, and for each element vertex add two neighbours in node's list. 要做到这一点,请遍历所有元素,并为每个元素顶点在节点列表中添加两个邻居。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM