예제 #1
0
        void SupportingLine(PointF s, Polygon p, PointToEdgeRelation side)
        {
            Rotation            rotation = side == PointToEdgeRelation.Right ? Rotation.Clockwise : Rotation.Counterclockwise;
            Vertex              a        = p.V;
            Vertex              b        = p.Neighbour(rotation);
            PointToEdgeRelation rel      = b.Point.Classify(s, a.Point);

            while (rel == side || rel == PointToEdgeRelation.Beyond || rel == PointToEdgeRelation.Between)
            {
                p.Advance(rotation);
                a   = p.V;
                b   = p.Neighbour(rotation);
                rel = b.Point.Classify(s, a.Point);
            }
        }
예제 #2
0
        bool PointInConvexPolygon(PointF s, Polygon p)
        {
            if (p.Size == 1)
            {
                return(s.X == p.Point.X && s.Y == p.Point.Y);
            }
            ;                                                 //(Math.Abs(s.X - p.Point.X) < 0.0001) && (Math.Abs(s.Y - p.Point.Y) < 0.0001);
            if (p.Size == 2)
            {
                PointToEdgeRelation rel = s.Classify(p.Point, p.Next.Point);
                return(rel == PointToEdgeRelation.Between ||
                       rel == PointToEdgeRelation.Origin ||
                       rel == PointToEdgeRelation.Destination);
            }

            Vertex start            = p.V;
            int    intersectsCnt    = 0;
            int    vertexIntersects = 0;

            for (int i = 0; i < p.Size; ++i)
            {
                var classification = s.Classify(p.Point, p.Next.Point);
                if (classification == PointToEdgeRelation.Destination || classification == PointToEdgeRelation.Origin ||
                    classification == PointToEdgeRelation.Between)
                {
                    p.SetV(start);
                    return(true);
                }
                if (LinesIntersect(p.Point, p.Next.Point, s, new PointF(pictureBox1.Width - 1, s.Y))
                    == IntersectionType.Intersects)
                {
                    ++intersectsCnt;
                }
                else if (LinesIntersect(p.Point, p.Next.Point, s, new PointF(pictureBox1.Width - 1, s.Y))
                         == IntersectionType.VertexIntersects)
                {
                    ++vertexIntersects;
                }
                p.Advance(Rotation.Clockwise);
            }

            p.SetV(start);
            intersectsCnt += vertexIntersects / 2;
            return(intersectsCnt % 2 != 0);
        }