Post Reply 
Solved: what is wrong with this LatLong->Distance code? A Trigonometry "feature".
10-12-2016, 08:14 PM
Post: #2
RE: Can you see what is wrong with this LatLong->Distance code?
It's rather difficult for me to decipher your code entirely. Therefore I've just taken the Haversine part and adjusted it a little bit. That is, I've done the HAV-function and the D2R in place. Further I replaced RR directly with the value of 6378.137 Km, I think that is correct because Haversine refers to the sphere and not to the ellipsoid.
Code:
EXPORT Haversine(LAT1,LON1,LAT2,LON2)
 BEGIN
  LOCAL RR:=6378.137;
  LOCAL DLON:=(LON2-LON1)/180*Pi;
  LOCAL DLAT:=(LAT2-LAT1)/180*Pi;
  LOCAL AA:=(sin(DLAT/2))^2 + 
   COS((LAT1)/180*Pi)*
   COS((LAT2)/180*Pi)*(sin(DLON/2))^2;
  LOCAL CC:=2*ASIN(MIN(1,√(AA)));//MIN 1 AVOIDS ROUNDING OUTRANGE
  LOCAL DD:=RR*CC;
  RETURN DD;
 END;

This works for me with known values. But I must admit, for rather long distances. If it works for you also then you should investigate the method of achieving "RR" with your "ESS{}". There might be the glitch.

HTH Günter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Can you see what is wrong with this LatLong->Distance code? - Guenter Schink - 10-12-2016 08:14 PM



User(s) browsing this thread: 1 Guest(s)