创建一个点的bean
public class Point { private double lat; private double lon; public double getLat() { return lat; } public void setLat(double lat) { this.lat = lat; } public double getLon() { return lon; } public void setLon(double lon) { this.lon = lon; } }
判断 点是否在图形中
public static boolean Contains(List<Point> points,Point point){ boolean result = false; for(int i =0 ; i<points.size()-1;i++){ if ((((points.get(i+1).getLon()<=point.getLon())&&(point.getLon()<points.get(i).getLon())) ||((points.get(i).getLon()<=point.getLon())&&(point.getLon()<points.get(i+1).getLon()))) &&(point.getLat() < (points.get(i).getLat()-points.get(i+1).getLat())*(point.getLon()-points.get(i+1).getLon()) /(points.get(i).getLon()-points.get(i+1).getLon())+points.get(i+1).getLat())) { result =! result; } } return result; }
时间: 2024-10-12 05:05:17