我发现BenDi this library从一组点创建了voronoi边缘。使用以下代码,我可以计算我的voronoi单元格的边缘。
using System;
using System.Collections.Generic;
using BenTools.Mathematics;
namespace Voronoi
{
class MainClass
{
public static void Main(string[] args)
{
Vector[] V = new Vector[4];
V[0] = new Vector(1.3, 2.8);
V[1] = new Vector(0.5, 2.8);
V[2] = new Vector(2, 1.8);
V[3] = new Vector(1, 3);
List<Vector> VoronoiSource = new List<Vector>();
VoronoiSource.AddRange(V);
VoronoiGraph Graph = Fortune.ComputeVoronoiGraph(VoronoiSource);
Console.WriteLine("Graph has {0} edges", Graph.Edges.Count);
foreach (var Edge in Graph.Edges)
{
Console.WriteLine("Edge: {0}", Edge.DirectionVector);
}
}
}
}
输出:
Graph has 5 edges
Edge: (-0,5547;-0,8321)
Edge: (0,8192;0,5735)
Edge: (0;1)
Edge: (0,5547;0,8321)
Edge: (-0,3714;0,9285)
如何将voronoi单元格计算为来自这些边缘的多边形?
答案 0 :(得分:1)
选择每条边的中点和每个站点的距离,然后对结果进行排序并选择第一个和第二个(当它们相等时)并将它们保存为多边形。对于边界,当然只有一个边缘。