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); }
bool PointsOnDifferentSides(PointF a, PointF b, PointF c, PointF d) { return(c.Classify(a, b) != d.Classify(a, b)); }