该点在多边形的内部或外部,或恰好在多边形的边界上. [英] the point is inside or outside or exactly on border of the polygon.

查看:65
本文介绍了该点在多边形的内部或外部,或恰好在多边形的边界上.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将实现一种算法,该算法将检查该点是在多边形的内部还是外部还是完全在多边形的边界上.

我有一个一个函数,但是只有当点在多边形内部时,它才会返回true.当点在多边形之外时返回false,但在点在多边形边界上时不返回true..

该功能在下面给出.

I would implement an algorithm which would check if the point is inside or outside or exactly on border of the polygon.

I have make one function but it will return true only when point is inside of polygon. and return false when point is outside of polygon but not return true when point is on border of the polygon..

This function is given below.

public static Boolean PointInPolygon(PointF p, List poly)
        {
            PointF p1, p2;
            bool inside = false;

            if (poly.Count < 3)
            {
                return inside;
            }
            PointF oldPoint = new PointF(

            poly[poly.Count - 1].X, poly[poly.Count - 1].Y);

            for (int i = 0; i < poly.Count; i++)
            {

                PointF newPoint = new PointF(poly[i].X, poly[i].Y);

                if (newPoint.X > oldPoint.X)
                {
                    p1 = oldPoint;
                    p2 = newPoint;
                }
                else
                {
                    p1 = newPoint;
                    p2 = oldPoint;
                }
                if ((newPoint.X < p.X) == (p.X <= oldPoint.X)
                    && ((long)p.Y - (long)p1.Y) * (long)(p2.X - p1.X)
                     < ((long)p2.Y - (long)p1.Y) * (long)(p.X - p1.X))
                {
                    inside = !inside;
                }
                oldPoint = newPoint;
            }
            return inside;
        }


因此,请告诉我其他方法或函数中的任何更改,这样便可以解决我的问题.


So please tell me any other way or any changed in my function, So it will solve my problem.

推荐答案

我现在已经多次阅读您的问题,只是为了确保我理解正确.
我将实现一种算法,该算法将检查该点是在多边形的内部还是外部或完全在多边形的边界上."
在二维空间的欧几里得几何中,一个点仅具有您提到的这三个选项,因此请放心,无论传递的参数是什么,您要做的就是return true;.

干杯!

—MRB
I''ve read your question multiple times now just to make sure that I understood it correctly.
"I would implement an algorithm which would check if the point is inside or outside or exactly on border of the polygon."
In Euclidean geometry in two dimensional space a point will only have these three options you mentioned so rest assured that regardless of the passed parameters all you have to do is return true;.

Cheers!

—MRB


这篇关于该点在多边形的内部或外部,或恰好在多边形的边界上.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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