资源简介

C#版的多边形拓扑结构算法,给定顶点及连接顶点的弧段信息,计算弧段-点关系表、多边形-弧段关系表。并且计算出各个多边形的面积,代码增加了对孤岛多边形的算法。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.InteropServices;

namespace Polygon
{
    public class CreatePolygons
    {
        public IList Points = new List();
        public IList Arcs = new List();
        public IList PointArcses = new List();
        public IList Polygons = new List();
        public int PolygonIndex;
        public ArcAngle MinAngle;
        public CreatePolygons(IList points IList arcs)
        {
            Points = points;
            Arcs = arcs;
        }

        public void MainCreatePolygons()
        {
            //建立点-弧段关系
            BuildPointArcs();

            //多边形自动构建算法
            foreach (var arc in Arcs.Where(arc => arc.TimesOfSearch==0))
            {
                BuildPolygons(arc);
            }
        }

        /// 
        /// 建立点-弧段关系
        /// 

        public void BuildPointArcs()
        {
            foreach (var point in Points)
            {
                var pointArcs = new PointArcs {PointId = point.Id};
                foreach (var arc in Arcs)
                {

                    var startPoint = arc.Points[0];
                    var endPoint = arc.Points[arc.Points.Count - 1];

                    if (point.Id == startPoint.Id || point.Id == endPoint.Id)
                    {
                        pointArcs.Arcs.Add(arc);
                    }
                }
                if (pointArcs.Arcs.Count != 0)
                    PointArcses.Add(pointArcs);
            }
        }
        
        /// 
        /// 从指定弧段开始构建多边形
        /// 

        /// 弧段
        public void BuildPolygons(Arc arc)
        {
            var polygons = new List();
            //正向(逆时针)构建第一个多边形
            var polygon = BuildPolygon(arc);
            polygon.Points = GetPolygonPoints(polygon);
            polygon.Area = Math.Abs(GetArea(polygon.Points));
            polygons.Add(polygon);

            //反向(顺时针)构建其它多边形
            for (var i = 0;i            {
                //从正向已经构建任意弧度开始构建
                if (Arcs[i].TimesOfSearch == 1)
                {
                    //改变当前弧段的构建方向
                    Arcs[i].Direction *= -1;
                    polygon = BuildPolygon(Arcs[i]);
                    if (polygon == null) return;
                    polygon.Points = GetPolygonPoints(polygon);
                    polygon.Area = Math.Abs(GetArea(polygon.Points));
                    polygons.Add(polygon);
                    //每次都从第一个弧段开始搜索
                    i = 0;
                }
            }

            //删除面积最大的一个多边形
            RemoveMaxPolygon(polygons);

            //给多边形增加编号
            foreach (var polygon1 in polygons)
            {
                polygon1

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-09-22 14:07  Topology\
     目录           0  2014-09-22 15:03  Topology\Polygon\
     文件         187  2014-09-18 11:06  Topology\Polygon\App.config
     文件       12376  2014-09-22 13:38  Topology\Polygon\CreatePolygons.cs
     文件        2353  2014-09-22 14:04  Topology\Polygon\DataModel.cs
     文件        2680  2014-09-19 10:20  Topology\Polygon\Polygon.csproj
     文件        3190  2014-09-22 15:03  Topology\Polygon\Program.cs
     目录           0  2014-09-20 08:11  Topology\Polygon\Properties\
     文件        1338  2014-09-18 11:06  Topology\Polygon\Properties\AssemblyInfo.cs
     文件        3335  2014-09-22 14:03  Topology\Polygon\Topology.cs
     目录           0  2014-09-20 08:11  Topology\Polygon\bin\
     目录           0  2014-09-20 08:11  Topology\Polygon\bin\Debug\
     文件       16896  2014-09-22 14:04  Topology\Polygon\bin\Debug\Polygon.exe
     文件         187  2014-09-18 11:06  Topology\Polygon\bin\Debug\Polygon.exe.config
     文件       46592  2014-09-22 14:04  Topology\Polygon\bin\Debug\Polygon.pdb
     文件       23168  2014-09-22 13:45  Topology\Polygon\bin\Debug\Polygon.vshost.exe
     文件         187  2014-09-18 11:06  Topology\Polygon\bin\Debug\Polygon.vshost.exe.config
     文件         490  2010-03-17 22:39  Topology\Polygon\bin\Debug\Polygon.vshost.exe.manifest
     目录           0  2014-09-25 09:57  Topology\Polygon\bin\Release\
     目录           0  2014-09-20 08:11  Topology\Polygon\obj\
     目录           0  2014-09-22 14:04  Topology\Polygon\obj\Debug\
     文件        6526  2014-09-21 21:13  Topology\Polygon\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         896  2014-09-22 13:45  Topology\Polygon\obj\Debug\Polygon.csproj.FileListAbsolute.txt
     文件        1755  2014-09-19 14:04  Topology\Polygon\obj\Debug\Polygon.csprojResolveAssemblyReference.cache
     文件       16896  2014-09-22 14:04  Topology\Polygon\obj\Debug\Polygon.exe
     文件       46592  2014-09-22 14:04  Topology\Polygon\obj\Debug\Polygon.pdb
     目录           0  2014-09-25 09:57  Topology\Polygon\obj\Debug\TempPE\
     文件           0  2014-09-18 11:07  Topology\Polygon\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2014-09-18 11:07  Topology\Polygon\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2014-09-18 11:07  Topology\Polygon\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     目录           0  2014-09-22 06:30  Topology\PolygonTest\
............此处省略57个文件信息

评论

共有 条评论