两个坐标之间的地理中点
我一直在使用 Moveable-Type 网站来帮助我进行一些地理坐标计算,它非常有用,但是,我在计算两个坐标之间的中点时遇到了一个错误。我的结果接近预期,但还不够接近:
posA = {47.64570362, -122.14073746}
posB = {47.64316917, -122.14032175}
预期结果(取自活字计算器)= 47°38′40″N, 122°08′26″W = {47.644444, -122.140556}< /code> 我的结果:
{49.6054801645915, -122.14052959995759}
这是我的代码:
private Geocoordinate MidPoint(Geocoordinate posA, Geocoordinate posB)
{
Geocoordinate midPoint = new Geocoordinate();
double dLon = DegreesToRadians(posB.Longitude - posA.Longitude);
double Bx = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Cos(dLon);
double By = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Sin(dLon);
midPoint.Latitude = RadiansToDegrees(Math.Atan2(Math.Sin(DegreesToRadians(posA.Latitude)) + Math.Sin(DegreesToRadians(posB.Latitude)),
Math.Sqrt((Math.Cos(DegreesToRadians(posA.Latitude)) + Bx) * (Math.Cos(DegreesToRadians(posA.Latitude))) + Bx) + By * By));
midPoint.Longitude = posA.Longitude + RadiansToDegrees(Math.Atan2(By, Math.Cos(DegreesToRadians(posA.Latitude)) + Bx));
return midPoint;
}
我有几个私有方法可以在度数和弧度之间进行相互转换。 例如,
private double DegreeToRadian(double angle)
{
return Math.PI * angle / 180.0;
}
我无法弄清楚为什么我的结果与纬度值相差几度。有什么想法吗?
谢谢
I have been using the Moveable-Type website to aid me in some Geocoordinate calcuations and it's been very useful, however, I have a bug in my calculation of the mid-point between two coordinates. My result is close to the expected, but not close enough:
posA = {47.64570362, -122.14073746}
posB = {47.64316917, -122.14032175}
expected result (taken from the movable type calculator) = 47°38′40″N, 122°08′26″W = {47.644444, -122.140556}
my result: {49.6054801645915, -122.14052959995759}
Here is my code:
private Geocoordinate MidPoint(Geocoordinate posA, Geocoordinate posB)
{
Geocoordinate midPoint = new Geocoordinate();
double dLon = DegreesToRadians(posB.Longitude - posA.Longitude);
double Bx = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Cos(dLon);
double By = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Sin(dLon);
midPoint.Latitude = RadiansToDegrees(Math.Atan2(Math.Sin(DegreesToRadians(posA.Latitude)) + Math.Sin(DegreesToRadians(posB.Latitude)),
Math.Sqrt((Math.Cos(DegreesToRadians(posA.Latitude)) + Bx) * (Math.Cos(DegreesToRadians(posA.Latitude))) + Bx) + By * By));
midPoint.Longitude = posA.Longitude + RadiansToDegrees(Math.Atan2(By, Math.Cos(DegreesToRadians(posA.Latitude)) + Bx));
return midPoint;
}
I've got a couple of private methods to do the conversion between Degrees and Radians and back.
E.g.
private double DegreeToRadian(double angle)
{
return Math.PI * angle / 180.0;
}
I can't work out why my results are off by a couple of degrees on the Lat value. Any ideas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你把一些括号放错了。我在代码中标记了这个地方。
You placed some parentheses wrong. I marked the place in the code.
一些方法(例如WGS84 约定)包括地球的扁率。 (至少这里是这么说的)
Some methods (eg WGS84 conventions) include oblateness of the earth. (at least that's what it says here)