我正在尝试使用带有 path2d 的多个顶点绘制任何类型的多边形形状,我想稍后使用 java.awt.geom.Area 查看确定点是否在其区域内
public static boolean is insideRegion(Region region, Coordinate coord){
Geopoint lastGeopoint = null;
GeoPoint firstGeopoint = null;
final Path2D boundary = new Path2D.Double();
for(GeoPoint geoponto : region.getGeoPoints()){
if(firstGeopoint == null) firstGeopoint = geoponto;
if(lastGeopoint != null){
boundary.moveTo(lastGeopoint.getLatitude(),lastGeopoint.getLongitude());
boundary.lineTo(geoponto.getLatitude(),geoponto.getLongitude());
}
lastGeopoint = geoponto;
}
boundary.moveTo(lastGeopoint.getLatitude(),lastGeopoint.getLongitude());
boundary.lineTo(firstGeopoint.getLatitude(),firstGeopoint.getLongitude());
final Area area = new Area(boundary);
Point2D point = new Point2D.Double(coord.getLatitude(),coord.getLongitude());
if (area.contains(point)) {
return true;
}
return false
}