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; }
return true;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)