public Voronoi VoronoiThreePoint(PointF A, PointF B, PointF C) { Voronoi v = new Voronoi(); PointF triEx; PointF mid; v.pList.Add(A); v.pList.Add(B); v.pList.Add(C); /* 三點共線 */ if (MathEx.isCollinear(v.pList[0], v.pList[1], v.pList[2])) { /* 將點排序 */ v.pList = MathEx.SortPointF(v.pList); /* 將邊無限延伸的做法 */ mid = MathEx.GetMidPointF(v.pList[0], v.pList[1]); v.vList.Add(new Edge(mid.Add(MathEx.GetNormalVector(v.pList[0], v.pList[1]).Multi(600)), mid.Add(MathEx.GetNormalVector(v.pList[1], v.pList[0]).Multi(600)), v.pList[0], v.pList[1])); mid = MathEx.GetMidPointF(v.pList[1], v.pList[2]); v.vList.Add(new Edge(mid.Add(MathEx.GetNormalVector(v.pList[1], v.pList[2]).Multi(600)), mid.Add(MathEx.GetNormalVector(v.pList[2], v.pList[1]).Multi(600)), v.pList[1], v.pList[2])); /* 將邊畫到邊界的做法 * mid = MathEx.GetMidPointF(v.pList[0], v.pList[1]); * v.vList.Add(new Edge(GetSidePointF(mid, mid.Add(MathEx.GetNormalVector(v.pList[1], v.pList[0]))), GetSidePointF(mid, mid.Add(MathEx.GetNormalVector(v.pList[0], v.pList[1]))))); * mid = MathEx.GetMidPointF(v.pList[1], v.pList[2]); * v.vList.Add(new Edge(GetSidePointF(mid, mid.Add(MathEx.GetNormalVector(v.pList[2], v.pList[1]))), GetSidePointF(mid, mid.Add(MathEx.GetNormalVector(v.pList[1], v.pList[2]))))); */ } else { /* 計算外心 */ triEx = MathEx.GetTriangleExcenterPointF(A, B, C); /* 將點依逆時針方向排序 */ v.pList = MathEx.SortVector(v.pList); for (int i = 0; i < v.pList.Count; i++) { mid = MathEx.GetMidPointF(v.pList[i], v.pList[(i + 1) % 3]); /* 將邊無限延伸的做法 */ v.vList.Add(new Edge(triEx, mid.Add(MathEx.GetNormalVector(v.pList[i], v.pList[(i + 1) % 3]).Multi(600)), v.pList[i], v.pList[(i + 1) % 3])); /* 將邊畫到邊界的做法 * v.vList.Add(new Edge(triEx, GetSidePointF(mid, mid.Add(MathEx.GetNormalVector(v.pList[i], v.pList[(i + 1) % 3]))))); */ } } return(v); }
public Voronoi VoronoiTwoPoint(PointF A, PointF B) { PointF mid = MathEx.GetMidPointF(A, B); Voronoi v = new Voronoi(); v.pList.Add(A); v.pList.Add(B); /* 將邊無限延伸的做法 */ v.vList.Add(new Edge(mid.Add(MathEx.GetNormalVector(A, B).Multi(600)), mid.Add(MathEx.GetNormalVector(B, A).Multi(600)), A, B)); /* 將邊畫到邊界的做法 * v.vList.Add(new Edge(GetSidePointF(mid, mid.Add(MathEx.GetNormalVector(A, B))), GetSidePointF(mid, mid.Add(MathEx.GetNormalVector(B, A))))); */ return(v); }
/// <summary> /// 取得中垂線 /// </summary> /// <param name="e">線</param> /// <returns>中垂線</returns> public static Edge GetBisector(this Edge e) { PointF mid = MathEx.GetMidPointF(e.A, e.B); return(new Edge(mid.Add(GetNormalVector(e.A, e.B).Multi(600)), mid.Add(GetNormalVector(e.B, e.A).Multi(600)), e.A, e.B)); }