• 大小: 544B
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: 其他
  • 标签: 多边形  c#  

资源简介

算法:判断一个Point 是否在多边形内部。给出点的坐标和多边形的坐标即可 public bool PointInBox(Point point, Point[] points) {....}

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;

    class Class2
    {
     
       
        //调用函数
        public bool PointInBox(Point point Point[] points)
        {

            int wn = 0 j = 0; 
            for (int i = 0; i < points.Length; i++)
            {
                if (i == points.Length - 1)
                    j = 0;
                else
                    j = j + 1; 


                if (points[i].Y <= point.Y)
                {
                    if (points[j].Y > point.Y)
                    {
                        if (isLeft(points[i] points[j] point) > 0)
                        {
                            wn++;
                        }
                    }
                }
                else
                {
                    if (points[j].Y <= point.Y)
                    {
                        if (isLeft(points[i] points[j] point) < 0)
                        {
                            wn--;
                        }
                    }
                }
            }
            if (wn == 0)
                return false;
            else
                return true;

        }

        //计算
        public int isLeft(Point P0 Point P1 Point P2)
        {
            int abc = ((P1.X - P0.X) * (P2.Y - P0.Y) - (P2.X - P0.X) * (P1.Y - P0.Y));
            return abc;

        }
    }


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

     文件       1549  2009-07-20 09:50  Class2.cs

----------- ---------  ---------- -----  ----

                 1549                    1


评论

共有 条评论