多边形方向及顶点凹凸性的判断


自己用C#实现的关于多边形方向及顶点凹凸性的判断的方法。里边的函数包括了构造多边形、方向判断、凹凸性判断。适合初学者学习参考之用。
资源截图
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;



namespace AnotherSolution
{
    public partial class Form1 : Form
    {
        bool flag = false;
        ArrayList selectPts = new ArrayList();
        Point[] resultPts;
        bool first = true;

        int XL = 0 XR = 0 YB = 0 YT = 0;  //分别记录pts中X的最左、最右,Y的最下、最上值
        Point[] tempPolygon;

        Point[] newPolygon;  //存储新生成的凸多边形
        int[] flagNum;       //存储多边形顶点的凹凸性,0表示凸顶点,-1表示凹顶点

        public Form1()
        {
            InitializeComponent();
            tempPolygon = new Point[4];
        }

        private void Form1_Load(object sender EventArgs e)
        {

        }

        private void 单击开始ToolStripMenuItem_Click(object sender EventArgs e)
        {
            flag = true;
        }

        private void Form1_MouseDown(object sender MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {

                if (flag == false)
                {
                    return;
                }
                Point pt = new Point(e.X e.Y);
                if (first == true)
                {
                    selectPts.Add(pt);  //v[0]=pt
                    //  selectPts.Add(pt);  //v[1]=pt
                    first = false;
                }
                else
                {
                    selectPts.Add(pt);
                    GetPoints(out resultPts);
                    Pen p = new Pen(Color.Blue 1);
                    Graphics g = this.CreateGraphics();
                    g.DrawLine(p resultPts[selectPts.Count - 2] resultPts[selectPts.Count - 1]);
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                Pen p = new Pen(Color.Blue 1);
                Graphics g = this.CreateGraphics();
                g.DrawLine(p resultPts[selectPts.Count - 1] resultPts[0]);
                first = true;
                selectPts.Clear();

                //    NewConvexPolygon(resultPts out tempPolygon);
                // int flaggs;
                // PolygonDirection(resultPts out flaggs);
               // VertexsConvexityConcavity(resultPts);
                PolygonConvexityConcavity(resultPts);
            }

        }

        Point[] GetPoints(out Point[] pts)
        {
            pts = new Point[selectPts.Count];
            for (int i = 0; i < selectPts.Count; i++)
            {
                pts[i] = (Point)selectPts[i];
            }
            return pts;
        }

        private void BubbleArray(int[] transArray)
        {
            int temp;
            for (int i = 0; i < transArray.Length - 1; i++)
            {
                for (int j = 0; j < transArray.Length - 1 - i; j++)
         

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4013  2013-09-29 16:06  AnotherSolutionAnotherSolutionAnotherSolution.csproj

     文件      13824  2013-10-06 13:18  AnotherSolutionAnotherSolutioninDebugAnotherSolution.exe

     文件      32256  2013-10-06 13:18  AnotherSolutionAnotherSolutioninDebugAnotherSolution.pdb

     文件      14328  2013-10-06 13:19  AnotherSolutionAnotherSolutioninDebugAnotherSolution.vshost.exe

     文件        490  2009-06-11 05:14  AnotherSolutionAnotherSolutioninDebugAnotherSolution.vshost.exe.manifest

     文件    4554752  2013-09-29 15:53  AnotherSolutionAnotherSolutionDevComponents.DotNetBar2.dll

     文件      10164  2013-10-06 13:18  AnotherSolutionAnotherSolutionForm1.cs

     文件       7450  2013-10-02 16:18  AnotherSolutionAnotherSolutionForm1.Designer.cs

     文件       6012  2013-10-02 16:18  AnotherSolutionAnotherSolutionForm1.resx

     文件        823  2013-10-06 13:19  AnotherSolutionAnotherSolutionobjDebugAnotherSolution.csproj.FileListAbsolute.txt

     文件        847  2013-10-02 16:18  AnotherSolutionAnotherSolutionobjDebugAnotherSolution.csproj.GenerateResource.Cache

     文件      13824  2013-10-06 13:18  AnotherSolutionAnotherSolutionobjDebugAnotherSolution.exe

     文件        180  2013-10-02 16:18  AnotherSolutionAnotherSolutionobjDebugAnotherSolution.Form1.resources

     文件      32256  2013-10-06 13:18  AnotherSolutionAnotherSolutionobjDebugAnotherSolution.pdb

     文件        180  2013-10-02 12:21  AnotherSolutionAnotherSolutionobjDebugAnotherSolution.Properties.Resources.resources

     文件       5891  2013-10-02 12:21  AnotherSolutionAnotherSolutionobjDebugResolveAssemblyReference.cache

     文件        507  2013-09-29 15:48  AnotherSolutionAnotherSolutionProgram.cs

     文件       1442  2013-09-29 15:48  AnotherSolutionAnotherSolutionPropertiesAssemblyInfo.cs

     文件       2859  2013-09-29 15:48  AnotherSolutionAnotherSolutionPropertiesResources.Designer.cs

     文件       5612  2013-09-29 15:48  AnotherSolutionAnotherSolutionPropertiesResources.resx

     文件       1100  2013-09-29 15:48  AnotherSolutionAnotherSolutionPropertiesSettings.Designer.cs

     文件        249  2013-09-29 15:48  AnotherSolutionAnotherSolutionPropertiesSettings.settings

     文件        935  2013-09-29 15:48  AnotherSolutionAnotherSolution.sln

    ..A..H.     17920  2013-10-06 13:19  AnotherSolutionAnotherSolution.suo

     目录          0  2013-09-29 15:48  AnotherSolutionAnotherSolutionobjDebugTempPE

     目录          0  2013-10-13 15:46  AnotherSolutionAnotherSolutioninDebug

     目录          0  2013-10-13 15:46  AnotherSolutionAnotherSolutionobjDebug

     目录          0  2013-10-13 15:46  AnotherSolutionAnotherSolutionin

     目录          0  2013-10-13 15:46  AnotherSolutionAnotherSolutionobj

     目录          0  2013-10-13 15:46  AnotherSolutionAnotherSolutionProperties

............此处省略5个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)