Algorithm for translating list of wallsections into coherent polygon

女生的网名这么多〃 提交于 2019-12-04 22:43:22

From your example I see that you draw a single polygon. You should call the method draw polygon (drawpoly(points)) multiple times for each separate polygon.

I think it's easier to draw the holes instead the wall, respecting the principle KISS.

To do that you can store the polygons (holes) you want to draw in a list. If we do an analysis about data, we see that bolded data show the begining and the end of an polygon.

<0,0><0,2><0,2><2,0><2,0><2,2><2,2><0,0> <1,1><1,1.5><1,1.5><1.5,1.5><1.5,1.5><1,1>

And we represent this in code, as shown below:

public List<List<GeoData>> Split(List<GeoData> points)
{
    List<List<GeoData>> polygons = new List<List<GeoData>>();
    GeoData firstPoint = null;
    List<GeoData> currentPolygon;

    foreach(var point in points)
    {
        if(firstPoint == null)
        {
            firstPoint = point;
            currentPolygon = new List<GeoData>();
            currentPolygon.Add(point);
        }
        else
        {
             currentPolygon.Add(point);
             if(point == firstPoint)
             {
                  firstPoint = null;
                  polygons.Add(currentPolygon);
             }
        }
    }
    return polygons;
}

Usage:

List<List<GeoData>> polygons = Split(points);

foreach(var polygon in polygons) 
{
    drawpoly(polygon);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!