【发布时间】: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.51degree -
尝试 debugging。首先,出了什么问题 - 如果角度是
90没问题,尝试添加小的 disturbance,比如91degree : 你在distanceX上有额外的gain 或loss 吗?distanceY呢?继续89度;然后将45- 正好 放在0和90案例之前... -
(distanceY / earthRadius) * 180 / Math.PI您可能缺少Sin或Cos等函数 -
@RuneJensen 为什么需要
earthRadius?
标签: c# math geolocation