GPS坐标添加角度不正确的仪表

时间:2019-03-29 15:53:21

标签: java gps

我有这个功能是想给现有坐标(纬度/经度)以给定角度添加以米(x和y)为单位的距离:

 * Calculates a new GPS coordinate from given coordinates and a given movement distances in meters
 *
 * @param lat0  the latitude to move from
 * @param long0 the longitude to move from
 * @param dx    the distance to move on the x axis in meters. Use positive values to move to the east(right) and negative values to move to the west(left)
 * @param dy    the distance to move on the y axis in meters. Use positive values to move to the north (up) and negative values to move to the south(down)
 * @return a new double array containing the target coordinates: [latitude, longitude]
 */
public double[] calculateCoordinatesAfterMove(double lat0, double long0, double dx, double dy) {
    double lat = lat0 + (180 / Math.PI) * (dy / 6378137);
    double lon = long0 + (180 / Math.PI) * (dx / 6378137) / Math.cos(Math.PI / 180.0 * lat0);
    return new double[]{lat, lon};
}

public double[] calculateCoodinatesAfterMove(Waypoint w, double dx, double dy, double angle) {
    return calculateCoordinatesAfterMove(w, dx * Math.cos(angle * Math.PI / 180), dy * Math.sin(angle * Math.PI / 180));
}

public double[] calculateCoordinatesAfterMove(double lat0, double long0, double dx, double dy, double angle) {
    return calculateCoordinatesAfterMove(lat0, long0, dx * Math.cos(angle * Math.PI / 180), dy * Math.sin(angle * Math.PI / 180));
}

我还有一个计算两个坐标之间方位的函数,并且检查了该函数是否正确。

问题在于上面的函数无法创建具有指定角度的航路点。
这是一个示例调用,其中我指定了64度角:

double[] resultMove = coordinateCalculator.calculateCoordinatesAfterMove(48.993268432102354, 8.395133104531464, 10, 5, 64);
        System.out.println(resultMove[0] + ", "  +resultMove[1]);
        System.out.println("Calculated angle: " + coordinateCalculator.calculateAngleBetweenWaypoints(
                48.993268432102354, 8.395133104531464, resultMove[0], resultMove[1]
        ));

计算出的航点为:

48.993308802123806, 8.395193120821242

以及此点与起点之间的计算角度正确,即44.2XXX度(在此处进行了检查:https://www.movable-type.co.uk/scripts/latlong.html

始终按示例所示通过纬度和经度,该纬度应为弧度。如果这种表示是度数,请纠正我:)

有人可以帮我为什么我的函数没有以所需角度返回航路点吗?

0 个答案:

没有答案