【问题标题】:Calculating a coordinate in an angle and distance from a coordinate计算与坐标的角度和距离的坐标
【发布时间】:2016-04-13 12:51:41
【问题描述】:

我为 IPoint 编写了这个扩展方法。

public static IPoint Offset(this IPoint point, double angle, double distanceInMeters)
{
    var radians = Math.PI * angle / 180;
    var distanceX = distanceInMeters * Math.Cos(radians);
    var distanceY = distanceInMeters * Math.Sin(radians);
    var earthRadius = 6371000;

    var y = point.Y + ((distanceY / earthRadius) * 180 / Math.PI);
    var x = point.X + ((distanceX / (earthRadius * Math.Cos(y * 180 / Math.PI))) * 180 / Math.PI);


    return new Point(x, y);
}

当我输入 0、90、180 和 270 的角度时,它工作正常,然后它返回距起点给定距离处的坐标。但是当我开始以一个不完全指向北、东等的角度时,我的距离是错误的。

我哪里出错了? 是否有一些库可供使用?

【问题讨论】:

  • 不太确定...但是...小心潜在的整数除法
  • int angle??? Double angle - 很有可能拥有,比如说,30.51 degree
  • 尝试 debugging。首先,出了什么问题 - 如果角度是 90 没问题,尝试添加小的 disturbance,比如 91 degree : 你在distanceX 上有额外的gainloss 吗? distanceY 呢?继续89度;然后将45 - 正好 放在090 案例之前...
  • (distanceY / earthRadius) * 180 / Math.PI 您可能缺少SinCos 等函数
  • @RuneJensen 为什么需要earthRadius

标签: c# math geolocation


【解决方案1】:

试试这个公式。我认为您应该将纬度和经度转换为弧度,然后再转换回度数。

    public static Point Offset(this Point point, double angle, double distanceInMeters)
    {
        double rad = Math.PI * angle / 180;

        double xRad = Math.PI * point.X / 180; // convert to radians
        double yRad = Math.PI * point.Y / 180;

        double R = 6378100; //Radius of the Earth in meters
        double x = Math.Asin(Math.Sin(xRad) * Math.Cos(distanceInMeters/ R)
                              + Math.Cos(xRad) * Math.Sin(distanceInMeters/ R) * Math.Cos(rad));

        double y = yRad + Math.Atan2(Math.Sin(rad) * Math.Sin(distanceInMeters/ R) * Math.Cos(xRad), Math.Cos(distanceInMeters/ R) - Math.Sin(xRad) * Math.Sin(x));

        x = x * 180 / Math.PI; // convert back to degrees
        y = y * 180 / Math.PI;

        return new Point(x, y);
    }

【讨论】:

  • 我试过你的公式,据我所知,结果和旧的一样。你知道计算两个坐标之间距离的公式吗,所以我可以写一个测试来验证结果。目前我正在将这些点绘制到谷歌地图中并使用他们的测量工具来验证......
  • @RuneJensen 很好奇,你能解释一下你是如何测试这个的吗?设置轴承可能有问题
猜你喜欢
  • 1970-01-01
  • 2011-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多