|
|
Home » Extra libraries, Code snippets, applications etc. » Applications created with U++ » Distance - geodesic - Vincenty - very accurate
Distance - geodesic - Vincenty - very accurate [message #25894] |
Thu, 18 March 2010 03:37  |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
This is a small app that incorporates the Vincenty formulas, Inverse and Direct, to calculate the geodesic distance on the ellipsoidal Earth, WGS84. It also calculates the starting and ending angles. Or with a starting point, direction and distance it will calculate the end point and final angle.
Input/output can be in any of the commonly used formats.
This can be used alone but interacts with a NASA WorldWind application written in Java through a socket.
This was previously done with Python, Java and now with C++ using Upp, a very good IDE/application.
http://www.nlneilson.com/geocalc.html
edit: updated link
[Updated on: Sun, 02 January 2011 13:01] Report message to a moderator
|
|
|
|
|
Re: Distance - geodesic - Vincenty - very accurate [message #25927 is a reply to message #25923] |
Sat, 20 March 2010 15:39   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
No, this can be used separately.
The latlon for the points can be typed or pasted in (then push Enter) for the calculations (Calculate->Distance). Many web sites have locations in latlon that can be copied and pasted into the app. It should be comma delimited so that may need to be added. There have been a few instances with the upp app where the text format was a problem, pasting the latlon into notepad and then into the app removed the formatting.
It will take data in decimal degrees, degrees minutes, deg min sec. And for distance meters, km, feet, mi, nmi.
The app can be used to convert also, km->mi, dms->deg, etc., and all to 8 decimal places or whatever you change the settings to. The data is retained in the app to 9 decimal places (degrees,meters), the Settings just change how it is displayed.
It works in Linux (Ubuntu 9.10) with Wine.
In theIDE it was much easier to do this than it was in Java.
[Updated on: Sat, 20 March 2010 16:46] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Re: Distance - geodesic - Vincenty - very accurate [message #25947 is a reply to message #25944] |
Sun, 21 March 2010 10:41   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
Mindtraveller wrote on Sun, 21 March 2010 08:44 | Cool.
What is the accuracy/drift of your calculations?
|
The Vincenty formulas are VERY accurate. With the Python code running it through a series of locations using the
Inverse formula and the returned values input to the Direct formula the result coincided usually to 10 decimal places
but did not exceed +/- 1 in the 9th decimal place. 9 decimal places is one billionth of a meter. The accuracy will not be
affected by the calculations. The accuracy of data input for locations, distance and starting angle, for all intent and
purposes, will determine the accuracy of the output.
The calculations are just math, no drift. Any "drift" would come from the input data.
Here is data on Tectonic Plate velocity or "drift"
http://hypertextbook.com/facts/ZhenHuang.shtml
using 5 cm per year
.05 / (365 * 24 * 60 * 60) = meters per second so the code
Distance<<=Format("m/sec %.9f", .05 / (365 * 24 * 60 * 60));
returns m/sec 0.000000002
2 in the 9th decimal place so it would take only 5 sec to make a
change in the 8th decimal place. 8 decimal places is the highest I have in the Distance app.
[Updated on: Sun, 21 March 2010 10:43] Report message to a moderator
|
|
|
Re: Distance - geodesic - Vincenty - very accurate [message #25951 is a reply to message #25947] |
Sun, 21 March 2010 18:11   |
 |
koldo
Messages: 3432 Registered: August 2008
|
Senior Veteran |
|
|
Hello nlnelson
Here there is the Chris Veness Vicentry direct formula
http://www.movable-type.co.uk/scripts/latlong-vincenty-direc t.html
The LGPL javascript code is this:
function destVincenty(lat1, lon1, brng, dist) {
var a = 6378137, b = 6356752.3142, f = 1/298.257223563; // WGS-84 ellipsiod
var s = dist;
var alpha1 = brng.toRad();
var sinAlpha1 = Math.sin(alpha1);
var cosAlpha1 = Math.cos(alpha1);
var tanU1 = (1-f) * Math.tan(lat1.toRad());
var cosU1 = 1 / Math.sqrt((1 + tanU1*tanU1)), sinU1 = tanU1*cosU1;
var sigma1 = Math.atan2(tanU1, cosAlpha1);
var sinAlpha = cosU1 * sinAlpha1;
var cosSqAlpha = 1 - sinAlpha*sinAlpha;
var uSq = cosSqAlpha * (a*a - b*b) / (b*b);
var A = 1 + uSq/16384*(4096+uSq*(-768+uSq*(320-175*uSq)));
var B = uSq/1024 * (256+uSq*(-128+uSq*(74-47*uSq)));
var sigma = s / (b*A), sigmaP = 2*Math.PI;
while (Math.abs(sigma-sigmaP) > 1e-12) {
var cos2SigmaM = Math.cos(2*sigma1 + sigma);
var sinSigma = Math.sin(sigma);
var cosSigma = Math.cos(sigma);
var deltaSigma = B*sinSigma*(cos2SigmaM+B/4*(cosSigma*(-1+2*cos2SigmaM*cos2SigmaM)-
B/6*cos2SigmaM*(-3+4*sinSigma*sinSigma)*(-3+4*cos2SigmaM*cos2SigmaM)));
sigmaP = sigma;
sigma = s / (b*A) + deltaSigma;
}
var tmp = sinU1*sinSigma - cosU1*cosSigma*cosAlpha1;
var lat2 = Math.atan2(sinU1*cosSigma + cosU1*sinSigma*cosAlpha1,
(1-f)*Math.sqrt(sinAlpha*sinAlpha + tmp*tmp));
var lambda = Math.atan2(sinSigma*sinAlpha1, cosU1*cosSigma - sinU1*sinSigma*cosAlpha1);
var C = f/16*cosSqAlpha*(4+f*(4-3*cosSqAlpha));
var L = lambda - (1-C) * f * sinAlpha *
(sigma + C*sinSigma*(cos2SigmaM+C*cosSigma*(-1+2*cos2SigmaM*cos2SigmaM)));
var revAz = Math.atan2(sinAlpha, -tmp); // final bearing
return new LatLon(lat2.toDeg(), lon1+L.toDeg());
}
Like the inverse, it seems easy to convert to C and LGPL license is pretty open.
Best regards
Iñaki
|
|
|
|
Re: Distance - geodesic - Vincenty - very accurate [message #25954 is a reply to message #25953] |
Sun, 21 March 2010 22:10   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
It may be 10+ years since I ported the Fortran to Python.
Then to C++ and later to Java, both are fast but I have the C++ optimized to run through the Inverse code in 10.7 micro seconds on a single core 1.60 Ghz notebook.
When I used this in Upp I just made that into a header file.
I don't recall what changes were necessary there, I did that with Eclipse CDT first, maybe just copied the header file from Eclipse to Upp.
I like to tinker with numbers, my major in college was Physics.
[Updated on: Sun, 21 March 2010 22:54] Report message to a moderator
|
|
|
Re: Distance - geodesic - Vincenty - very accurate [message #25974 is a reply to message #25935] |
Mon, 22 March 2010 22:20   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
Didier wrote on Sat, 20 March 2010 22:29 | But why not publish a linux version ...?
|
I was able to get Upp/theIDE to run in Ubuntu 10.04b.
Trying to make a linux version of Distance.exe the first error was re #include <windows.h>, just commented that and here is an excerpt of the errors:
error: call of overloaded ‘abs(double)’ is ambiguous
/usr/include/stdlib.h:766: note: candidates are: int abs(int)
/home/neil/upp/uppsrc/Core/Core.h:300: note: Upp::int64 abs(Upp::int64)
/usr/include/c++/4.4/cstdlib:170: note: long long int __gnu_cxx::abs(long long int)
/usr/include/c++/4.4/cstdlib:139: note: long int std::abs(long int)
/home/neil/MyApps/Distance/VincFormula.h: In function ‘std::string
It make take some time but I will try to get a Linux version that will run without Wine.
[Updated on: Mon, 22 March 2010 22:25] Report message to a moderator
|
|
|
|
Re: Distance - geodesic - Vincenty - very accurate [message #25976 is a reply to message #25975] |
Mon, 22 March 2010 22:57   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
Thanks Koldo, the fabs took care of that error.
Now I get:
/home/neil/MyApps/Distance/Distance.cpp:280: error: extra qualification ‘MyApp::’ on member ‘Key’
at this line:
bool MyApp::Key(dword key, int count){
edit: I deleted "MyApp::" and it works in debug.
I will make a few changes like the default dir for the file chooser, I had that as C:\ for win.
I changed it so it has a frame and can be dragged.
[Updated on: Mon, 22 March 2010 23:14] Report message to a moderator
|
|
|
|
Re: Distance - geodesic - Vincenty - very accurate [message #25979 is a reply to message #25894] |
Mon, 22 March 2010 23:44   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
Here is the Linux version.
edit: The link was removed, still have a glitch when downloaded.
I have not tried all the functions yet, what I have tried worked.
I will change the dir for the file chooser later, that is only used to interact with another app.
This can be used by itself.
Now the hard part, making a Help file to explain how it can be used. Since it is menu driven most functions are self explanatory.
One thing to remember is after typing or pasting in the latlon for a point (or distance,angle) press Enter, I forget sometimes.
The latlon should be comma separated.
Neil
[Updated on: Tue, 23 March 2010 04:04] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Fri Apr 25 17:47:46 CEST 2025
Total time taken to generate the page: 0.01183 seconds
|
|
|