7
$\begingroup$

I'm trying to calculate a bearing (degrees, distance) between two points, a and b. From Google Earth I have two points and the following code to calculate the bearing. The input coordinates is in the WGS84 datum (degree, minutes, seconds).

a = {{56, 11, 27.65}, {10, 14, 49.78}};
b = {{56, 11, 27.78}, {10, 14, 54.03}};

aLat = a[[1, 1]] + a[[1, 2]]/60 + a[[1, 3]]/3600;
aLong = a[[2, 1]] + a[[2, 2]]/60 + a[[2, 3]]/3600;
bLat = a[[1, 1]] + b[[1, 2]]/60 + b[[1, 3]]/3600;
bLong = b[[2, 1]] + b[[2, 2]]/60 + b[[2, 3]]/3600;

aPos = GeoPosition[{aLat, aLong}];
bPos = GeoPosition[{bLat, bLong}];

In[90]:= pejling = {GeoDirection[aPos, bPos], GeoDistance[aPos, bPos]}

Out[90]= {Quantity[86.8595, "AngularDegrees"], 
 Quantity[73.4046, "Meters"]}

So ~87º and ~74 meters.

However, in Google Earth I get ~80º and 146 meters.

enter image description here

I can't really figure out why there's a difference. I mean, even if the altitude has something to say, it can't possible be that much. I know the area and it's quite flat.

Also, the heading is somewhat close and the distance in GE is approx 2x the one from Mathematica, but I can't deduce anything from that.

Any ideas?

$\endgroup$
  • $\begingroup$ @andre I see... But I wonder why there's a difference in my example, and more importantly, which bearing should I trust? $\endgroup$ – Argo Mar 19 '16 at 22:17
  • 1
    $\begingroup$ In the calculation of blat there is an erroneous a term. This is not the cause of your problem, but wrong nevertheless. $\endgroup$ – Sjoerd C. de Vries Mar 20 '16 at 0:17
11
$\begingroup$

The coordinates a = {{56, 11, 27.65}, {10, 14, 49.78}}; b = {{56, 11, 27.78}, {10, 14, 54.03}}; doesn't correspond to what is on the picture.

Try This :

a = {{56, 11, 27.65}, {10, 14, 49.78}};
b = {{56, 11, 27.78}, {10, 14, 54.03}};

aLat = a[[1, 1]] + a[[1, 2]]/60 + a[[1, 3]]/3600;
aLong = a[[2, 1]] + a[[2, 2]]/60 + a[[2, 3]]/3600;
bLat = b[[1, 1]] + b[[1, 2]]/60 + b[[1, 3]]/3600;
bLong = b[[2, 1]] + b[[2, 2]]/60 + b[[2, 3]]/3600;

With[{aLats = ToString[aLat, InputForm],
  aLongs = ToString[aLong, InputForm],
  bLats = ToString[bLat, InputForm],
  bLongs = ToString[bLong, InputForm]},
 Import["http://maps.google.com/maps/api/staticmap?path=color:\
0xff0000ff|weight:5|" <> aLats <> "," <> aLongs <> "|" <> bLats <> 
   "," <> bLongs <> 
   "&size=400x400&sensor=false&maptype=satellite&markers=" <> aLats <>
    "," <> aLongs <> "|" <> bLats <> "," <> bLongs]
 ]

enter image description here

The last code use Google Earth API which may become obsolete. In that case one can use the Google Map API, and by the way too URLExecute[] :

a = {{56, 11, 27.65}, {10, 14, 49.78}};
b = {{56, 11, 27.78}, {10, 14, 54.03}};

aLat = a[[1, 1]] + a[[1, 2]]/60 + a[[1, 3]]/3600;
aLong = a[[2, 1]] + a[[2, 2]]/60 + a[[2, 3]]/3600;
bLat = a[[1, 1]] + b[[1, 2]]/60 + b[[1, 3]]/3600;
bLong = b[[2, 1]] + b[[2, 2]]/60 + b[[2, 3]]/3600;
aLats = ToString[aLat, InputForm]
aLongs = ToString[aLong, InputForm]
bLats = ToString[bLat, InputForm]
bLongs = ToString[bLong, InputForm]
centerLats = ToString[(aLat + bLat)/2, InputForm]
centerLongs = ToString[(aLong + bLong)/2, InputForm]    

URLExecute["http://maps.googleapis.com/maps/api/staticmap", \
{"maptype" -> "satellite", 
  "center" -> centerLats <> "," <> centerLongs, "zoom" -> "17", 
  "size" -> "600x300", "format" -> "png", 
  "markers" -> 
   "color:blue|" <> aLats <> "," <> aLongs <> "|" <> bLats <> "," <> 
    bLongs}, "PNG"]

enter image description here

You can also enter the coordinates manually in Google Earth (in the form x°y'z ''). It gives the same result.

Infos :

  • Use of the Google Elevation API is subject to a limit of 2,500 requests per day

  • I have measured some 100m athletics tracks around the world. First I point the beginning and the end of the tracks with Google Earth, then I export the 2 points to Mathematica, and then I use GeoDistance[]. Here are the amazing results :

    {Quantity[100.109, "Meters"], Quantity[99.9603, "Meters"],
    Quantity[100.01, "Meters"], Quantity[99.9818, "Meters"]}

$\endgroup$
  • $\begingroup$ Awesome, thanks! One small request: Let's say I have coordinates start-coordinates {a1, a2, a3, a4} and end-coordinates {b1, b2, b3, b4}. How would one calculate all the bearings from a1 to b1, a2 to b2 and so on? I've tried using a for-loop for extracting the degrees/minutes/seconds and converting to decimal, but without luck. $\endgroup$ – Argo Mar 20 '16 at 12:40
  • $\begingroup$ @Argo You can do for example : MapThread[GeoDistance,{{a1,a2,a3,a4},{b1,b2,b3,b4}}] $\endgroup$ – andre314 Mar 20 '16 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.