【发布时间】:2013-10-14 12:26:40
【问题描述】:
我有两个列表:List<Vertex> points,包含顶点 (x,y) 和一个列表 List<Triangles> triangles,包含三角形的节点 (a,b,c)。因此,a,b,c 是定义三角形的点的索引。
我现在想轻松计算这些。例如。我想为每个三角形获取从点 a 到点 b 的所有向量:
list<vector> p21;
foreach triangle t p21.add(new vector(p[t.b].x-p[t.a].x, p[t.b].y-p[t.a].y));
但我确信使用 linq 可以非常优雅地完成此操作。
类似的东西(不使用矢量,而是使用“顶点”)
List<Vertex> = (from triangle in triangles select a,b and from point in points select new { pi[b].x-pi[a], pi[b].x-pi[a] };
我该怎么做?
【问题讨论】:
-
我假设您希望三角形是唯一的?
-
三角形应该是唯一的......我提前检查了这个(delaunay三角剖分)。类似于 List
bc = (from triangle in triangles select new Vertex( points[triangle.b].x - points[triangle.c].x, points[triangle.b].x - points[triangle.c ].y)).ToList() 有效还是有更好/更快的选择?