Solved: what is wrong with this LatLong->Distance code? A Trigonometry "feature".
10-12-2016, 08:14 PM
Post: #2
 Guenter Schink Senior Member Posts: 505 Joined: Dec 2013
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
 « Next Oldest | Next Newest »

 Messages In This Thread Solved: what is wrong with this LatLong->Distance code? A Trigonometry "feature". - StephenG1CMZ - 10-12-2016, 06:20 PM RE: Can you see what is wrong with this LatLong->Distance code? - Guenter Schink - 10-12-2016 08:14 PM RE: Can you see what is wrong with this LatLong->Distance code? - StephenG1CMZ - 10-12-2016, 09:46 PM RE: Can you see what is wrong with this LatLong->Distance code? - Guenter Schink - 10-13-2016, 10:12 AM RE: Can you see what is wrong with this LatLong->Distance code? - StephenG1CMZ - 10-13-2016, 04:52 PM RE: Can you see what is wrong with this LatLong->Distance code? Trigonometry bug? - Tim Wessman - 10-13-2016, 05:31 PM RE: Can you see what is wrong with this LatLong->Distance code? Trigonometry bug? - Guenter Schink - 10-14-2016, 09:53 AM RE: Can you see what is wrong with this LatLong->Distance code? Trigonometry bug? - StephenG1CMZ - 10-13-2016, 08:58 PM RE: Can you see what is wrong with this LatLong->Distance code? A Trigonometry &quo... - StephenG1CMZ - 10-17-2016, 10:17 PM RE: Solved: what is wrong with this LatLong->Distance code? A Trigonometry "fe... - StephenG1CMZ - 10-23-2016, 06:41 PM

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