Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
nlneilson is currently offline  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 #25922 is a reply to message #25894] Sat, 20 March 2010 02:24 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Here is a page with a better description of what the app does.
http://www.nlneilson.com/distance.html

And at the bottom of that page is a link to a few images.
http://www.nlneilson.com/distance_images.html

theIDE, Upp and the help on this forum was great.
Re: Distance - geodesic - Vincenty - very accurate [message #25923 is a reply to message #25922] Sat, 20 March 2010 08:23 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello nlneilson

It seems your program has to work over other one that shows a satellite image. Is not it?


Best regards
Iñaki
Re: Distance - geodesic - Vincenty - very accurate [message #25927 is a reply to message #25923] Sat, 20 March 2010 15:39 Go to previous messageGo to next message
nlneilson is currently offline  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 #25931 is a reply to message #25927] Sat, 20 March 2010 21:31 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
It works in Linux (Ubuntu 9.10) with Wine.

Why does it not work directly without Wine?


Best regards
Iñaki
Re: Distance - geodesic - Vincenty - very accurate [message #25934 is a reply to message #25931] Sat, 20 March 2010 22:21 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
In Ubuntu double clicking the file it tries to open with "Archive Manager". I don't know how to run it without Wine.
Re: Distance - geodesic - Vincenty - very accurate [message #25935 is a reply to message #25931] Sat, 20 March 2010 22:29 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Koldo,

Quote:

Why does it not work directly without Wine?

The compiled app is a '.exe' (windows) so in linux => you need wine to execute it.

But I'm sure you already know that Wink

But why not publish a linux version or even the source code ?
And this app could become a widget.
Re: Distance - geodesic - Vincenty - very accurate [message #25938 is a reply to message #25935] Sun, 21 March 2010 00:52 Go to previous messageGo to next message
nlneilson is currently offline  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 or even the source code ?

When I get Ubuntu up again on my main computer I will download upp for Linux and try making a .elf to run directly in Linux.

Just this morning I tried to update 9.10 to 10.04b2, that didn't work.
I downloaded and burned an ISO and it locks on boot, a known issue that was "fixed" a few days ago but have been unable to get the fix. Probably just install 9.10 until 10.04 release comes out, about 5 weeks.

Much of the code is proprietary, that is one reason it was never released in Java. The "decompiler" jad easily puts it back to source code. A Java .jar is not really compiled, it is an interpreted language that is "compiled" or turned into machine code, at run time by the jre.
At least in C++ that would be more work to decompile. It may be easier for someone to port the Vincenty code from Fortran to C++ than try to hack an .exe.
http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf
The rest of the code is mostly manual labor except for the parsing.

Does the Linux version of Upp come with or has links to the correct version of MinGW or whatever compiler will work?
I will probably need to read several threads to get that working.
Re: Distance - geodesic - Vincenty - very accurate [message #25941 is a reply to message #25938] Sun, 21 March 2010 07:57 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello nlneison

At least in C++ that would be more work to decompile. It may be easier for someone to port the Vincenty code from Fortran to C++ than try to hack an .exe.

Do you mean that you call a windows .exe that includes the Vincenty code?

If yes it seems the Chris Veness javascript LGPL code here http://www.movable-type.co.uk/scripts/latlong-vincenty.html is easy to port to C.


Best regards
Iñaki
Re: Distance - geodesic - Vincenty - very accurate [message #25944 is a reply to message #25941] Sun, 21 March 2010 08:44 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Cool.
What is the accuracy/drift of your calculations?
Re: Distance - geodesic - Vincenty - very accurate [message #25946 is a reply to message #25941] Sun, 21 March 2010 10:12 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
koldo wrote on Sun, 21 March 2010 07:57

Hello nlneison

At least in C++ that would be more work to decompile. It may be easier for someone to port the Vincenty code from Fortran to C++ than try to hack an .exe.

Do you mean that you call a windows .exe that includes the Vincenty code?

If yes it seems the Chris Veness javascript LGPL code here http://www.movable-type.co.uk/scripts/latlong-vincenty.html is easy to port to C.


I think that is pretty close to what I meant.

I have not tried to decompile an .exe or .dll file but know it can be done but it takes experience and work to do it. So what I was trying to say was the Distance app code was proprietary and that for someone to port the Fortran code would seem to be easier than decompiling a compiled .exe file.

Chris Veness's javascript code is just for the Inverse Formula and he has a copyright even though it is LGPL. Then you would need the Direct Formula.

There are examples on the web in different languages. I think a Govt. agency has code in another language, as well as the Fortran, where there would be no copyright.
Re: Distance - geodesic - Vincenty - very accurate [message #25947 is a reply to message #25944] Sun, 21 March 2010 10:41 Go to previous messageGo to next message
nlneilson is currently offline  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 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
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 #25953 is a reply to message #25951] Sun, 21 March 2010 20:22 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Yes, that is good.

It still may not be much more work to start with the Vincenty formula, especially in the .html format where you can copy and paste, and port the Fortran to C++ to avoid even the LGPL issue.

Also note that T. Vincenty was not responsible for the math for the formulas. He just took the formulas that could be done by hand and modified it to Fortran so it could be done on the early computers.
Re: Distance - geodesic - Vincenty - very accurate [message #25954 is a reply to message #25953] Sun, 21 March 2010 22:10 Go to previous messageGo to next message
nlneilson is currently offline  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 Go to previous messageGo to next message
nlneilson is currently offline  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 #25975 is a reply to message #25974] Mon, 22 March 2010 22:24 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
nlneilson wrote on Mon, 22 March 2010 22:20

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 am
	biguous
/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.

Hello nlnelson

In Gcc (linux and MinGW) you would have to use fabs() instead of abs() to avoid this error.

You can filter this errors compiling with MinGW in Windows.


Best regards
Iñaki
Re: Distance - geodesic - Vincenty - very accurate [message #25976 is a reply to message #25975] Mon, 22 March 2010 22:57 Go to previous messageGo to next message
nlneilson is currently offline  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 #25977 is a reply to message #25976] Mon, 22 March 2010 23:11 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
nlneilson wrote on Mon, 22 March 2010 22:57

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.

Hello nlnelson

Very probably you have inserted the code inside a class.
That means that adding class name in function is useless, so you simply has to remove "MyApp::" in the left of function definition.

For example this will get the same error:

class EditFileFolder : public EditString {
typedef EditFileFolder CLASSNAME;
protected:
	bool EditFileFolder::Key(dword key, int rep) {     // EditFileFolder:: is useless
		if (key == K_ENTER) {	// Catch the ENTER
			DoGo();
			return false;
		} else
			return EditField::Key(key, rep);
	}


Best regards
Iñaki
Re: Distance - geodesic - Vincenty - very accurate [message #25979 is a reply to message #25894] Mon, 22 March 2010 23:44 Go to previous messageGo to previous message
nlneilson is currently offline  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

Previous Topic: Google Translator
Next Topic: How to load dll
Goto Forum:
  


Current Time: Fri Mar 29 00:44:53 CET 2024

Total time taken to generate the page: 0.02941 seconds