从voronoi边缘获取多边形 [英] Getting polygons from voronoi edges

查看:71
本文介绍了从voronoi边缘获取多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了此库由BenDi从一组点创建voronoi边缘.使用以下代码,我可以计算我的voronoi细胞的边缘.

I found this library by BenDi to create voronoi edges from a set of points. With the following code I can compute the edges of my voronoi cells.

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细胞计算为多边形?

How can I compute the voronoi cells as polygons from these edges?

推荐答案

选择每个边缘的中点和到每个站点的距离,然后对结果进行排序并选择第一个和第二个(当它们相等时)并将它们保存为多边形.对于边界,当然只有1条边.

Pick the midpoint of each edge and the distance to each site then sort the result and pick the first and second (when they are equal) and save them into polygons. For the borders there is of course only 1 edge.

这篇关于从voronoi边缘获取多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆