public static ArrayList<LatLong> initAbData(double A_lat, double A_lng, double B_lat, double B_lng, double distance, int abpoint_direction) { int abpoint_count = 1; double yA = MercatorProjection.latitudeToY(A_lat); double xA = MercatorProjection.longitudeToX(A_lng); double yB = MercatorProjection.latitudeToY(B_lat); double xB = MercatorProjection.longitudeToX(B_lng); ArrayList<LatLong> latLongs = new ArrayList<>(); LatLong latLong = new LatLong(A_lat, A_lng); LatLong latLong2 = new LatLong(B_lat, B_lng); latLongs.add(latLong); latLongs.add(latLong2); double abpoint_distance = MercatorProjection.getMercatorDistance(latLongs, distance); arrayList.clear(); Vector2D abpoint_vector_ab = new Vector2D(xB - xA, yB - yA); Point abpoint_B = new Point(xB, yB); Vector2D abpoint_vector_bc_unit = getAbpoint_vector_bc_unit(abpoint_vector_ab); Vector2D vector2D = abpoint_vector_bc_unit.multiply(abpoint_direction).multiply(abpoint_distance); do { getDestinalXY(abpoint_B, abpoint_vector_ab, vector2D, abpoint_count); abpoint_count++; } while (abpoint_count <= 58); latLongs.clear(); latLongs.add(latLong); latLongs.add(latLong2); for (Point vector2D1 : arrayList) { double longitude = MercatorProjection.xToLongitude(vector2D1.x); double latitude = MercatorProjection.yToLatitude(vector2D1.y); LatLong latLongAB = new LatLong(latitude, longitude); latLongs.add(latLongAB); // System.out.println(latitude+"xxx"+longitude); } return latLongs; } private static ArrayList<Point> arrayList = new ArrayList<>(); // private static ArrayList<LatLong> latLongs = new ArrayList<>(); //获取AB方向的一组航线 private static void getDestinalXY(Point abpoint_B, Vector2D abpoint_vector_ab, Vector2D vector2D, int abpoint_count) { if (abpoint_count % 2 != 0) { abpoint_B.x += vector2D.x; abpoint_B.y += vector2D.y; Point pointResult = new Point(abpoint_B.x, abpoint_B.y); arrayList.add(pointResult); } else { double pow = Math.pow(-1, abpoint_count >> 1); Vector2D multiply = abpoint_vector_ab.multiply(pow); abpoint_B.x += multiply.x; abpoint_B.y += multiply.y; Point pointResult = new Point(abpoint_B.x, abpoint_B.y); arrayList.add(pointResult); } } //获取AB垂直方向的单位向量 private static Vector2D getAbpoint_vector_bc_unit(Vector2D abpoint_vector_ab) { // caculate bc vector Vector2D ab_vector_vertical = new Vector2D(1.0f, -abpoint_vector_ab.x / abpoint_vector_ab.y); Vector2D ab_vector_vertical_unit = ab_vector_vertical.normalize(); double result = ab_vector_vertical_unit.dotProduct(abpoint_vector_ab); if (result != 0) { ab_vector_vertical = new Vector2D(-abpoint_vector_ab.y / abpoint_vector_ab.x, 1.0f); ab_vector_vertical_unit = ab_vector_vertical.normalize(); } Vector2D abpoint_vector_bc_unit; if ((abpoint_vector_ab.x * ab_vector_vertical_unit.y - abpoint_vector_ab.y * ab_vector_vertical_unit.x) > 0) { abpoint_vector_bc_unit = ab_vector_vertical_unit; } else { abpoint_vector_bc_unit = ab_vector_vertical_unit.reverse(); } return abpoint_vector_bc_unit; }