public bool Equals(FTriangle t) { if (Object.ReferenceEquals(t, null)) { return(false); } if (Object.ReferenceEquals(this, t)) { return(true); } if (this.GetType() != t.GetType()) { return(false); } return(p1 == t.p1 && p2 == t.p2 && p3 == t.p3 || p1 == t.p2 && p2 == t.p3 && p3 == t.p1 || p1 == t.p3 && p2 == t.p1 && p3 == t.p2 || p1 == t.p3 && p2 == t.p2 && p3 == t.p1 || p1 == t.p2 && p2 == t.p1 && p3 == t.p3 || p1 == t.p1 && p2 == t.p3 && p3 == t.p2); }
public bool hasCommonPoints(FTriangle t) { return(p1 == t.p1 || p1 == t.p2 || p1 == t.p3 || p2 == t.p1 || p2 == t.p2 || p2 == t.p3 || p3 == t.p1 || p3 == t.p2 || p3 == t.p3); }
private static void addElementToRedundanciesMap(Dictionary <FTriangle, bool> hashMap, FTriangle t) { hashMap[t] = !hashMap.ContainsKey(t); }
public static List <FTriangle> DelaunayTriangulation(List <PointF> points, RectangleF boundingBox) { if (points == null) { return(new List <FTriangle>()); } List <FTriangle> triangleSet = new List <FTriangle>(); // 巨大な外部三角形をリストに追加 FTriangle hugeTriangle = getHugeTriangle(boundingBox); triangleSet.Add(hugeTriangle); try { foreach (PointF p in points) { Dictionary <FTriangle, bool> tmpTriangleSet = new Dictionary <FTriangle, bool>(); for (int i = 0; i < triangleSet.Count; i++) { FTriangle t = triangleSet[i]; // その外接円を求める。 FCircle c = t.GetCircumscribedCircles(); if (FMath.SqDistance(c.center, p) <= c.radius * c.radius) { addElementToRedundanciesMap(tmpTriangleSet, new FTriangle(p, t.p1, t.p2)); addElementToRedundanciesMap(tmpTriangleSet, new FTriangle(p, t.p2, t.p3)); addElementToRedundanciesMap(tmpTriangleSet, new FTriangle(p, t.p3, t.p1)); triangleSet.RemoveAt(i); i--; } } foreach (var kv in tmpTriangleSet) { if (kv.Value) { triangleSet.Add(kv.Key); } } } // 最後に、外部三角形の頂点を削除 for (int i = 0; i < triangleSet.Count; i++) { FTriangle t = triangleSet[i]; // もし外部三角形の頂点を含む三角形があったら、それを削除 if (hugeTriangle.hasCommonPoints(t)) { triangleSet.RemoveAt(i); i--; } } return(triangleSet); } catch (Exception) { return(null); } }