算法翻译wallsections名单成连贯的多边形 [英] Algorithm for translating list of wallsections into coherent polygon

查看:213
本文介绍了算法翻译wallsections名单成连贯的多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我点的列表,在描述对多边形,这样的:

I have a list of points that in pairs describe a polygon, like this:

< 0,0>< 0,1>℃下, 1>< 1,0>< 1,0>< 1,1>< 1,1>< 0,0>这是一个正方形。需要注意的是每一对点描述了行,以便我们的广场上编造出来的线

<0,0><0,1><0,1><1,0><1,0><1,1><1,1><0,0> which is a square. Note that each pair of points describes a line so our square is made up out of the lines

<的;< 0,0>< 0,1 >>< ;< 0,1>< 1,0 >><< 1,0>< 1,1 >><< 1,1>< 0,0 >>

<<0,0><0,1>><<0,1><1,0>><<1,0><1,1>><<1,1><0,0>>

然而,我不得不得出这些多边形当有问题的点都是正确的秩序,没有小孔,工作正常。不幸的是这有时会出错,当输入像

I do however have to draw these polygons which works fine when the points in question are all properly in order and there are no holes. Unfortunatly this sometimes goes wrong when the input is like

< 0,0>< 0,1>< 1,1>< 0,0>< ; 0,1>&下; 1,0>&下; 1,0>&下; 1,1>将所得的多边形是怪异或当有在

<0,0><0,1><1,1><0,0><0,1><1,0><1,0><1,1> and the resulting polygon is weird or when there are several holes in the

< 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>

<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>

在这种情况下绘制这些多边形以drawpoly(点)的naitive事情是行不通的。

In these situations the naitive thing of drawing these polygons with a drawpoly(points) is not going to work.

这是在C#和输入的是在现实中列表<地理数据> ,其中地理数据包含2个点(和其他一些MISQ数据)。对于输出我的想法是做一个列表和一个List>,其中第一组点的是外线,第二列表是孔,将这项工作?我需要做一些额外的计算与多边形其他然后就画,但我认为,这将是最容易与空穴的特别清单。

This is in c# and the input is in reality a List<GeoData> where GeoData contains 2 points (and some other misq data). For the output I was thinking of making a List and a List> where the first set of points are the outer line and the second list is the holes, would that work? I do need to do some extra computations with the polygons other then just drawing but I think that will be easiest with a special list of holes.

下面是一个例子:

左边是我目前得到右边是输入。

On the left is what I currently get on the right is the input.

推荐答案

从你的榜样,我看你画一个多边形。你应该调用方法绘制多边形( drawpoly(点))多次给每个单独的多边形。

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.

我觉得它更容易绘制的漏洞的不是墙,尊重原则 KISS

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>

<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);
}

这篇关于算法翻译wallsections名单成连贯的多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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