首页 > 解决方案 > 如何计算地图上第二个点的坐标?

问题描述

示例图片我有地图上第一个点的坐标,点之间有距离,并且相对于基点有旋转度数(来自指南针)。请告诉我如何计算地图上第二点的坐标?

我试图用公式来找到点之间的距离并重建它,但我不知道如何使用旋转度数,最后我完全糊涂了。

标签: javamathgps

解决方案


This question can have a variety of answers, depending on what exactly you mean by latitude, longitude and compass, and what accuracy you require.

The simplest case is that the latitude and longitude are relative to a spherical model of the earth (with earth radius R) and that sub metre accuracy is enough. Then we can compute:

lat1Rad = lat1 * pi/180 // latitude of source point in radians
lon1Rad = lon1 * pi/180 // longitude of source point in radians
slat = R  // R is earth radius 
slon = R*cos( lat1Rad)
bRad = compass*pi/180  // compass reading in radians
dN = dist*cos( bRad)   // change in northing
dE = dist*sin( bRad)   // change in easting
lat2Rad = lat1Rad + dN/slat  // target latitude in radians
lon2Rad = remainder( lon2Rad + dE/slon, 2.0*pi)  // target longitude in radians

This is just plane geometry, except that the scale of longitude (ie how much a small change in longitude is worth in metres) varies with the cosine of the latitude.

That should be good to better than a millimetre over a distance of 100m, and better than a centimetre for distances up to 1km.

You might wonder at the call to remainder in computing the longitiude. It's not required (ie could be omitted) in your specific case, but over the years I've got into the habit of writing code that will work even if you are close to 180 East (or West)

Some more complicated cases: Your lat and long could be relative to an ellipsoidal model of the earth (for example WGS84). In that case the slat and slon variables need to be computed differently, using the details of the ellipsoid used.

Your compass is a magnetic device. In that case you need to correct the compass for magnetic variation (aka magnetic declination) to get a reading relative to true north.

You require higher accuracy. It is usual in geodesy to interpret the problem to be about following the geodesic (great circle for a spherical earth) between the points. Then the code needs to be rewritten entirely. For a spherical earth there are (relatively) simple formulae to use. For a ellipsoidal earth there is code around that will do this computation.


推荐阅读