public static void GetPoints(List<Point> points) { if (points.Count == 0) return; int highestx = points[0].X; int highesty = points[0].Y; int lowestx = points[0].X; int lowesty = points[0].Y; for (int i = 0; i < points.Count; i++) { if (points[i].X > highestx) highestx = points[i].X; if (points[i].Y > highesty) highesty = points[i].Y; if (points[i].X < lowestx) lowestx = points[i].X; if (points[i].Y < lowesty) lowesty = points[i].Y; } for (int x = lowestx; x < highestx; x++) { for (int y = lowesty; y < highesty; y++) { if (PointInPolygon(new Point(x, y), points)) { obstacles[x, y] = 1; } } } } static bool PointInPolygon(Point p, List<Point> poly) { Point p1, p2; bool inside = false; if (poly.Count < 3) { return inside; } Point oldPoint = new Point( poly[poly.Count - 1].X, poly[poly.Count - 1].Y); for (int i = 0; i < poly.Count; i++) { Point newPoint = new Point(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; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)