Solved: what is wrong with this LatLong->Distance code? A Trigonometry "feature".
10-12-2016, 09:46 PM (This post was last modified: 10-12-2016 11:05 PM by StephenG1CMZ.)
Post: #3
 StephenG1CMZ Senior Member Posts: 979 Joined: May 2015
RE: Can you see what is wrong with this LatLong->Distance code?
Thank you for taking the time to look at this.
When I first saw your code I was thinking the lower-case Sin was exact and avoiding a rounding error - but it doesn't fix this example, which is still 1 km rather than 54 km.

For spherical calculations I usually use an average of polar and equatorial radius, (actually. (2a+b)/3), or repeat the calculations for both - but that detail isn't significant.

Example data:
http://www.ga.gov.au/geodesy/datums/vinc...nverse.jsp

Update: a missing atan2 call is added - the reported distance is still 1 km. Actually, that is probably just equivalent to the previous line.

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   //INSERT LINES   LOCAL DD;   CC:=2*ATAN2YX(√(AA),√(1-AA^2));   //END INSERT   DD:=RR*CC;//REMOVE LOCAL      RETURN DD;  END;  EXPORT HAVERSINES()  BEGIN   LOCAL DIST;   PRINT();   DIST:=Haversine(−37°57′3.72030″,144°25′29.52440″,−37°39′10.15610″,143°55′35​.38390″);//EXPECTS 54972m   PRINT(DIST+" km");   PRINT("EXPECTED: 54972m");//VINCENTY AUSTRALIA    END;

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
 « 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)