ボロノイ分割


適当にボロノイ分割を試す。
もう少し中身読むかな

https://github.com/PouletFrit/csDelaunay

http://en.wikipedia.org/wiki/Fortune’s_algorithm

csDelaunay

var rand = new Random(DateTime.Now.Millisecond);

List<Vector2f> v2f = new List<Vector2f>();
double xmin, ymin, xmax, ymax;
xmin = ymin = xmax = ymax = double.NaN;
      
for (int i = 0; i < 1000; i++)
{
  int x = rand.Next(0, 1000);
  int y = rand.Next(0, 1000);
  v2f.Add(new Vector2f(x, y));

  if (double.IsNaN(xmin))
  {
    xmin = x;
    ymin = y;
    xmax = x;
    ymax = y;
  }
  else
  {
    xmin = Math.Min(x, xmin);
    ymin = Math.Min(y, ymin);
    xmax = Math.Max(x, xmax);
    ymax = Math.Max(y, ymax);
  }//end if
}//end loop

Rectf rect = new Rectf
(
  (float)xmin, 
  (float)ymin, 
  (float)(xmax - xmin),
  (float)(ymax-ymin) 
);


Console.WriteLine("CREATE TABLE #tmp (SHP GEOMETRY);");
            
using (var voronoi = new Voronoi(v2f, rect))
{
    var dig = voronoi.VoronoiDiagram();
    foreach (var item in dig)
    {
      Console.Write("INSERT INTO #tmp (SHP) VALUES(GEOMETRY::STGeomFromText('LINESTRING(");
      Console.Write("{0} {1},{2} {3})'", item.p0.x, item.p0.y, item.p1.x, item.p1.y);
      Console.Write(", 4326))");
      Console.Write(Environment.NewLine);
    }
}//end v
カテゴリー: 開発 タグ: パーマリンク