• 大小: 1.34MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-20
  • 语言: C#
  • 标签: 计算几何  凹凸性  C#  

资源简介

自己用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  AnotherSolution\AnotherSolution\AnotherSolution.csproj

     文件      13824  2013-10-06 13:18  AnotherSolution\AnotherSolution\bin\Debug\AnotherSolution.exe

     文件      32256  2013-10-06 13:18  AnotherSolution\AnotherSolution\bin\Debug\AnotherSolution.pdb

     文件      14328  2013-10-06 13:19  AnotherSolution\AnotherSolution\bin\Debug\AnotherSolution.vshost.exe

     文件        490  2009-06-11 05:14  AnotherSolution\AnotherSolution\bin\Debug\AnotherSolution.vshost.exe.manifest

     文件    4554752  2013-09-29 15:53  AnotherSolution\AnotherSolution\DevComponents.DotNetBar2.dll

     文件      10164  2013-10-06 13:18  AnotherSolution\AnotherSolution\Form1.cs

     文件       7450  2013-10-02 16:18  AnotherSolution\AnotherSolution\Form1.Designer.cs

     文件       6012  2013-10-02 16:18  AnotherSolution\AnotherSolution\Form1.resx

     文件        823  2013-10-06 13:19  AnotherSolution\AnotherSolution\obj\Debug\AnotherSolution.csproj.FileListAbsolute.txt

     文件        847  2013-10-02 16:18  AnotherSolution\AnotherSolution\obj\Debug\AnotherSolution.csproj.GenerateResource.Cache

     文件      13824  2013-10-06 13:18  AnotherSolution\AnotherSolution\obj\Debug\AnotherSolution.exe

     文件        180  2013-10-02 16:18  AnotherSolution\AnotherSolution\obj\Debug\AnotherSolution.Form1.resources

     文件      32256  2013-10-06 13:18  AnotherSolution\AnotherSolution\obj\Debug\AnotherSolution.pdb

     文件        180  2013-10-02 12:21  AnotherSolution\AnotherSolution\obj\Debug\AnotherSolution.Properties.Resources.resources

     文件       5891  2013-10-02 12:21  AnotherSolution\AnotherSolution\obj\Debug\ResolveAssemblyReference.cache

     文件        507  2013-09-29 15:48  AnotherSolution\AnotherSolution\Program.cs

     文件       1442  2013-09-29 15:48  AnotherSolution\AnotherSolution\Properties\AssemblyInfo.cs

     文件       2859  2013-09-29 15:48  AnotherSolution\AnotherSolution\Properties\Resources.Designer.cs

     文件       5612  2013-09-29 15:48  AnotherSolution\AnotherSolution\Properties\Resources.resx

     文件       1100  2013-09-29 15:48  AnotherSolution\AnotherSolution\Properties\Settings.Designer.cs

     文件        249  2013-09-29 15:48  AnotherSolution\AnotherSolution\Properties\Settings.settings

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

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

     目录          0  2013-09-29 15:48  AnotherSolution\AnotherSolution\obj\Debug\TempPE

     目录          0  2013-10-13 15:46  AnotherSolution\AnotherSolution\bin\Debug

     目录          0  2013-10-13 15:46  AnotherSolution\AnotherSolution\obj\Debug

     目录          0  2013-10-13 15:46  AnotherSolution\AnotherSolution\bin

     目录          0  2013-10-13 15:46  AnotherSolution\AnotherSolution\obj

     目录          0  2013-10-13 15:46  AnotherSolution\AnotherSolution\Properties

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

评论

共有 条评论