地理空间坐标和距离(以公里为单位) [英] Geospatial coordinates and distance in kilometers

查看:36
本文介绍了地理空间坐标和距离(以公里为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是这个问题的后续行动.

我似乎陷入了困境.基本上,我需要能够来回转换以参考标准度数系统中的坐标,或者通过测量沿国际日期变更线从南极向北的距离,然后从日期的那个点开始向东的距离线.为了做到这一点(以及一些更一般的距离测量的东西),我有一种方法来确定两个纬度/经度点之间的距离,另一种方法需要一个纬度/经度点、一个航向和一个距离,然后返回该课程结束时的纬度/经度点.

I seem to be stuck on this. Basically, I need to be able to convert back and forth to referring to coordinates either in the standard degree system OR by measuring a distance north from the south pole along the international date line, and then a distance east starting from that point on the date line. To do this (as well as some more general distance-measuring stuff), I have one method for determining the distance between two lat/lon points, and another method that takes a lat/lon point, a heading and a distance, and returns the lat/lon point at the end of that course.

这是我定义的两个静态方法:

Here are the two static methods I've defined:

/* Takes two lon/lat pairs and returns the distance between them in kilometers.
*/
public static double distance (double lat1, double lon1, double lat2, double lon2) {
    double theta = toRadians(lon1-lon2);
    lat1 = toRadians(lat1);
    lon1 = toRadians(lon1);
    lat2 = toRadians(lat2);
    lon2 = toRadians(lon2);

    double dist = sin(lat1)*sin(lat2) + cos(lat1)*cos(lat2)*cos(theta);
    dist = toDegrees(acos(dist)) * 60 * 1.1515 * 1.609344 * 1000;

    return dist;
}

/* endOfCourse takes a lat/lon pair, a heading (in degrees clockwise from north), and a distance (in kilometers), and returns
 * the lat/lon pair that would be reached by traveling that distance in that direction from the given point.
 */
public static double[] endOfCourse (double lat1, double lon1, double tc, double dist) {
    double pi = Math.PI;
    lat1 = toRadians(lat1);
    lon1 = toRadians(lon1);
    tc = toRadians(tc);
    double dist_radians = toRadians(dist / (60 * 1.1515 * 1.609344 * 1000));
    double lat = asin(sin(lat1) * cos(dist_radians) + cos(lat1) * sin(dist_radians) * cos(tc));
    double dlon = atan2(sin(tc) * sin(dist_radians) * cos(lat1), cos(dist_radians) - sin(lat1) * sin(lat));
    double lon = ((lon1-dlon + pi) % (2*pi)) - pi;
    double[] endPoint = new double[2];
    endPoint[0] = lat; endPoint[1] = lon;
    return endPoint;
}

这是我用来测试它的函数:

And here's the function I'm using to test it:

public static void main(String args[]) throws java.io.IOException, java.io.FileNotFoundException {
    double distNorth = distance(0.0, 0.0, 72.0, 0.0);
    double distEast = distance(72.0, 0.0, 72.0, 31.5);
    double lat1 = endOfCourse(0.0, 0.0, 0.0, distNorth)[0];
    double lon1 = endOfCourse(lat1, 0.0, 90.0, distEast)[1];
    System.out.println("end at: " + lat1 + " / " + lon1);
    return;
}

结束于"值应为 appx.72.0/31.5.但相反,我得到大约 1.25/0.021.

The "end at" values should be appx. 72.0 / 31.5. But instead I'm getting approximately 1.25 / 0.021.

我想我一定是遗漏了一些愚蠢的东西,忘记在某处转换单位,或者其他什么......任何帮助将不胜感激!

I assume I must be missing something stupid, forgetting to convert units somewhere, or something... Any help would be greatly appreciated!

更新 1:

我已经(正确地)编写了返回米的距离函数,但是在评论中错误地写了公里......当我今天回到它时,这当然让我感到困惑.无论如何,现在已经修复了,我已经修复了 endOfCourse 方法中的因式分解错误,而且我还意识到我也忘记了在该方法中将弧度转换回度数.无论如何:虽然看起来我现在得到了正确的纬度数(71.99...),但经度数却很差(我得到的是 3.54 而不是 11.5).

I had (correctly) written the distance function to return meters, but wrote kilometers in the comments by mistake ... which of course confused me when I came back to it today. Anyway, now that's fixed, and I've fixed the factoring error in the endOfCourse method, and I also realized I'd forgotten to convert back to degrees from radians in that method too. Anyway: while it appears I'm now getting the correct latitude number (71.99...), the longitude number is way off (I get 3.54 instead of 11.5).

更新 2:我在测试中有一个错字,如下所述.它现在已在代码中修复.然而,经度数仍然是错误的:我现在得到的是 -11.34 而不是 11.5.我认为这些行一定有问题:

UPDATE 2: I had a typo in the test, as mentioned below. It's now fixed in the code. The longitude number is still, however, wrong: I'm now getting -11.34 instead of 11.5. I think there must be something wrong with these lines:

double dlon = atan2(sin(tc) * sin(dist_radians) * cos(lat1), cos(dist_radians) - sin(lat1) * sin(lat));
double lon = ((lon1-dlon + pi) % (2*pi)) - pi;

推荐答案

代码中的幻数很严重.表达式:

You've got a serious case of the magic numbers in the code. The expression:

 (60 * 1.1515 * 1.609344 * 1000)

出现两次,但没有太多解释.在一些帮助下:1.609344 是一英里的公里数;60 是一个学位的分钟数;1000是一公里的米数;1.1515 是海里的法定英里数(感谢 DanM).一海里是赤道纬度一分钟的长度.

appears twice, but there's not much explanation of it. With some help: 1.609344 is the number of kilometres in a mile; 60 is the number of minutes in a degree; 1000 is the number of metres in a kilometre; and 1.1515 is the number of statute miles in a nautical mile (thanks, DanM). One nautical mile is the length of one minute of latitude at the equator.

我假设您使用的是球形地球模型,而不是球形地球?代数不够复杂,不能成为椭球体.

I assume you are using a spherical earth model, rather than a spheroidal earth? The algebra isn't complex enough to be spheroidal.

第一个公式 - 两个纬度和经度对之间的转换 - 很奇怪.您需要 delta-lat (Δλ) 和 delta-lon (Δφ) 来找出答案.此外,对之间的距离:

The first formula - conversion between two latitude and longitude pairs - is odd. You need both delta-lat (Δλ) and delta-lon (Δφ) to sort out the answer. Further, the distance between the pairs:

(60° N, 30° W), (60° N, 60° W)
(60° N, 60° W), (60° N, 90° W)

应该是一样的 - 但我很确定你的代码会产生不同的答案.

should be the same - but I'm pretty sure your code produces different answers.

所以,我认为你需要回到你的球面三角参考材料,看看你做错了什么.(我需要一些时间才能找到我关于这个主题的书——它需要从它所在的任何一个盒子中打开.)

So, I think you need to go back to your spherical trigonometry reference materials and see what you're doing wrong. (It would take me a while to find my book on the subject - it would need to be unpacked from whichever box it is in.)

[...时间过去了...拆包完成...]

给定一个球面三角形,在顶点和边 a 处有角度 ABCb, c 对着那些顶点(即边a是从BC 等),余弦公式为:

Given a spherical triangle with angles A, B, C at the vertices and sides a, b, c opposite those vertices (that is, side a is from B to C, etc.), the Cosine Formula is:

cos a = cos b . cos c + sin b . sin c . cos A

将此应用于问题,我们可以将给定的两个点称为BC,并创建一个在A处具有直角的直角球面三角形.

Applying this to the problem, we can call the two points given B and C, and we create a right spherical triangle with a right angle at A.

最糟糕的 ASCII 艺术:

ASCII art at its worst:

                  + C
                 /|
                / |
            a  /  | b
              /   |
             /    |
            /     |
         B +------+ A
              c

c等于经度差;b边等于纬度差;角度 A 是 90°,所以 cos A = 0.因此,我相信 a 的等式是:

The side c is equal to the difference in longitude; the side b is equal to the difference in latitude; the angle A is 90°, so cos A = 0. Therefore, I believe an equation for a is:

cos a = cos Δλ . cos Δφ + sin Δλ . sin Δφ . cos 90°

a = arccos (cos Δλ . cos Δφ)

以弧度为单位的角度a 然后通过乘以地球的半径转换为距离.或者,给定 a 度数(以及度数的小数),那么 60 海里对应一个度数,因此 60 * 1.1515 法定英里数和 60 * 1.1515 * 1.609344 公里对应一个度数.除非您想要以米为单位的距离,否则我认为不需要 1000 倍.

The angle a in radians is then converted to a distance by multiplying by the radius of the Earth. Alternatively, given a in degrees (and fractions of a degree), then there are 60 nautical miles to one degree, hence 60 * 1.1515 statute miles, and 60 * 1.1515 * 1.609344 kilometres to one degree. Unless you want the distance in metres, I don't see a need for the factor of 1000.

Paul Tomblin 指出 Aviation Formulary v1.44 作为方程式的来源- 事实上,它就在那里,还有一个数值更稳定的版本,适用于位置差异很小的情况.

Paul Tomblin points to Aviation Formulary v1.44 as a source of the equation - and indeed, it is there, together with a more numerically stable version for when the difference in position is small.

转到基本的三角学,我们也知道:

Going to basic trigonometry, we also know that:

cos (A - B) = cos A . cos B + sin A . sin B

在我给出的公式中应用两次很可能最终得到航空公式中的公式.

Applying that twice in the equation I gave might well end up at the formula in the Aviation Formulary.

(我的参考:"天文学:原理与实践,第四版",AE Roy 和 D Clarke(2003 年);我的副本是 1977 年的第一版,Adam Hilger,ISBN 0-85274-346-7.)

(My reference: "Astronomy: Principles and Practice, Fourth Edition" by A E Roy and D Clarke (2003); my copy is the first edition from 1977, Adam Hilger, ISBN 0-85274-346-7.)

注意查看(谷歌)'define:海里"';根据定义,现在一海里似乎是 1852 米(1.852 公里).乘数 1.1515 对应于海里的旧定义,大约为 6080 英尺.使用比例为 10 的 bc,我得到:

NB Check out (Google) 'define:"nautical mile"'; it appears that a nautical mile is now 1852 m (1.852 km) by definition. The multiplier 1.1515 corresponds to the old definition of the nautical mile as approximately 6080 ft. Using bc with a scale of 10, I get:

(1852/(3*0.3048))/1760
1.1507794480

哪个因素适合你取决于你的基础是什么.

Which factor works for you depends on what your basis is.

从第一原理看第二个问题,我们的设置略有不同,我们需要另一个"球面三角方程,即正弦公式:

Looking at the second problem from first principles, we have a slightly different setup, and we need the 'other' spherical trigonometry equation, the Sine Formula:

sin A   sin B   sin C
----- = ----- = -----
sin a   sin b   sin c

改编上一张图:

                  + C
                 /|
                / |
            a  /  | b
           |  /   |
           |X/    |
           |/     |
         B +------+ A
              c

给定起点B,角度X = 90º - B,长度(角度)a,角度A = 90°.你所追求的是b(纬度增量)和c(经度增量).

You are given starting point B, angle X = 90º - B, length (angle) a, and angle A = 90°. What you are after is b (the delta in latitude) and c (the delta in longitude).

所以,我们有:

sin a   sin b
----- = ----
sin A   sin B

或者

        sin a . sin B
sin b = -------------
            sin A

或者,由于 A = 90°,sin A = 1,sin B = sin (90° - X) = cos X:

Or, since A = 90°, sin A = 1, and sin B = sin (90° - X) = cos X:

sin b = sin a . cos X

这意味着您将行进的距离转换为角度a,取其正弦值,乘以航向方向的余弦值,然后取结果的反正弦值.

That means you convert the distance travelled into an angle a, take the sine of that, multiply by the cosine of the course direction, and take the arcsine of the result.

给定ab(刚刚计算)和AB,我们可以应用余弦公式得到c.请注意,我们不能简单地重新应用正弦公式来获得 c,因为我们没有 C 的值,并且因为我们正在使用球面三角,所以不是 C = 90° - B 的方便规则(球面三角形中的角度之和可以大于 180°;考虑一个所有角度都等于 90° 的等边球面三角形,这是完全可行的).

Given a, b (just calculated) and A and B, we can apply the cosine formula to get c. Note that we cannot simply re-apply the sine formula to get c since we don't have the value of C and, because we're playing with spherical trigonometry, there is no convenient rule that C = 90° - B (the sum of the angles in a spherical triangle can be greater than 180°; consider an equilateral spherical triangle with all angles equal to 90°, which is perfectly feasible).

这篇关于地理空间坐标和距离(以公里为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆