嗨,我目前正在尝试根据2个经度/纬度点(开腹)和距离来计算经度/纬度点,而我目前已经做到了:
double EARTH_RADIUS = 6378137.0;
double longitude1 = 4.062787;
double latitude1 = 49.243828;
double x1 = EARTH_RADIUS * (Math.cos(Math.toRadians(latitude1)) * Math.cos(Math.toRadians(longitude1)));
double y1 = EARTH_RADIUS *(Math.cos(Math.toRadians(latitude1)) * Math.sin(Math.toRadians(longitude1)));
double longitude2 = 4.062023;
double latitude2 = 49.243851;
double x2 = EARTH_RADIUS * (Math.cos(Math.toRadians(latitude2)) * Math.cos(Math.toRadians(longitude2)));
double y2 = EARTH_RADIUS *(Math.cos(Math.toRadians(latitude2)) * Math.sin(Math.toRadians(longitude2)));
System.out.println(x1 + " " + y1);
System.out.println(x2 + " " + y2);
double[][] positions = new double[][] { { x1, y1 }, { x2, y2 } };
double[] distances = new double[] { 10.0, 10.0};
NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(new TrilaterationFunction(positions, distances), new LevenbergMarquardtOptimizer());
Optimum optimum = solver.solve();
double[] centroid = optimum.getPoint().toArray();
System.out.println(Arrays.toString(centroid));
我正在使用此库https://github.com/lemmingapex/trilateration来说明我的观点。
将经度和纬度点转换为笛卡尔计划,并使用库在其上获取点,从而得到以下输出结果:
[INFO] GCLOUD: 4153447.729890433 295011.4801210027
[INFO] GCLOUD: 4153449.72871882 294955.95932889543
[INFO] GCLOUD: [4153448.7293046266, 294983.7197249491]
因此,现在我正尝试将此点转换为纬度和经度点,以将其放置在Google Map上,但是我不知道如何执行该操作,并且如果Java库已经存在以进行双向化,那么我不知道该怎么做?
编辑:
所以我做到了:
private static final double EARTH_RADIUS = 6371;
private static final int X = 0;
private static final int Y = 1;
private static final int Z = 2;
public static double[] triangulation(double lat0, double lon0, double r0, double lat1, double lon1, double r1) {
double[] p1 = latlon2cartesian(lat0, lon0);
double[] p2 = latlon2cartesian(lat1, lon1);
double[][] positions = new double[][] { { p1[X], p1[Y], p1[Z] }, { p2[X], p2[Y], p2[Z] } };
double[] distances = new double[] { r0, r1};
NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(new TrilaterationFunction(positions, distances), new LevenbergMarquardtOptimizer());
Optimum optimum = solver.solve();
double[] centroid = optimum.getPoint().toArray();
System.out.println(Arrays.toString(p1));
System.out.println(Arrays.toString(p2));
System.out.println(Arrays.toString(centroid));
return cartesian2latlon(centroid[X], centroid[Y], centroid[Z]);
}
private static double[] latlon2cartesian(double lat, double lon) {
lat = Math.toRadians(lat);
lon = Math.toRadians(lon);
return new double[] { Math.cos(lon) * Math.cos(lat) * EARTH_RADIUS, Math.sin(lon) * Math.cos(lat) * EARTH_RADIUS, Math.sin(lat) * EARTH_RADIUS };
}
private static double[] cartesian2latlon(double x, double y, double z) {
return new double[] { Math.toDegrees(Math.asin(z / EARTH_RADIUS)), Math.toDegrees(Math.atan2(y, x)) };
}
但是我没有得到正确的值:
System.out.println(Arrays.toString(Bilateration.triangulation(49.243828, 4.062787, 5.0, 49.243851, 4.062023, 6.5)));
我明白了:
[49.2453096100026, 3.9213007384886387]
在附近(2公里外),但是该点应该在49.24385234064716,4.062335368930235左右。