bool isPointInPolygon(Point point, List<Point> polygon) {
  bool inside = false;
  int n = polygon.length;
  for (int i = 0, j = n - 1; i < n; j = i++) {
    double xi = polygon[i].x, yi = polygon[i].y;
    double xj = polygon[j].x, yj = polygon[j].y;
    bool intersect = ((yi > point.y) != (yj > point.y)) &&
                     (point.x < (xj - xi) * (point.y - yi) / (yj - yi) + xi);
    if (intersect) {
      inside = !inside;
    }
  }
  return inside;
}
Popular Tag
Share:

Yorum yap