lon/lat distance

Bj

Addon Developer
Addon Developer
Donator
Joined
Oct 16, 2007
Messages
1,886
Reaction score
11
Points
0
Location
USA-WA
Website
www.orbiter-forum.com
I meant that I could have a generic vessel class, "Dynamic object", create a vessel of that class on the ground, in the focus vessel's FOV, and load a tree mesh for it, so that vessel simulates a tree scenery.

That sounds cool,

Is that why you wanted to know distance? like if the dg was 5 km away it will display the vessel?

:cheers:
 

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
Yes, but I found a work around for it, at least while dealing with orbital rendering. It's more difficult when you create vessels on the ground, because you have to give lat/lon instead of relative pos and relative vel. I still need to figure that out. If you know the lat/lon if your vessel, how would you find the coordinates say after a 5 km offset?
 

tl8

Addon Developer
Addon Developer
Tutorial Publisher
Joined
Oct 16, 2007
Messages
3,645
Reaction score
25
Points
88
Location
Gold Coast QLD
I think using 111.12 km/ degree would be your best bet
 

Bj

Addon Developer
Addon Developer
Donator
Joined
Oct 16, 2007
Messages
1,886
Reaction score
11
Points
0
Location
USA-WA
Website
www.orbiter-forum.com
Yes, but I found a work around for it, at least while dealing with orbital rendering. It's more difficult when you create vessels on the ground, because you have to give lat/lon instead of relative pos and relative vel. I still need to figure that out. If you know the lat/lon if your vessel, how would you find the coordinates say after a 5 km offset?

Well, not sure on how the lat/lon works quite right, but one way is to have a circle and use Pythagorean thereom

A^2+ b^2 = c^2

so c^2 - B^2 = A^2

A and B being A is change in x or lat and B being change in y or lon

that should work...


*Edit*

This is a clip of a more mathematical version of it; (using sin, cos)
Pythagorean_Theorem.jpg

unitci50.gif
becomes
unitci51.gif
 

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
But I already know the distance, distance is easy to figure out. I have to find lon/lat coordinates of where I have to create a random vessel. But perhaps not...I just got an idea. :speakcool: Thanks for your help BJ and tl8. :beach:
 

Scrooge McDuck

Addon Developer
Addon Developer
Joined
Mar 18, 2008
Messages
515
Reaction score
30
Points
28
Location
The Netherlands
Website
orbitermap.no-ip.org
Sorry, I noticed this thread a little late, in case you are still in the need of alternatives:

To calculate the distance of two objects when given their lat/long.


I always use this: (wrong, see post below for correction)

Code:
  d := 2 * arcsin(sqrt( sqr( sin((lat1-lat2)/2) ) + cos(lat1)*cos(lat2)*  sqr(sin((long1-long2)/2)) ));


  if sin(long2-long1) < 0 then
    a   :=       arccos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)))
  else
    a   := 2*pi- arccos((sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)));

  Distance:= a * 180/Pi;
It appears to work pretty good.

regards,
mcduck
 

Scrooge McDuck

Addon Developer
Addon Developer
Joined
Mar 18, 2008
Messages
515
Reaction score
30
Points
28
Location
The Netherlands
Website
orbitermap.no-ip.org
I always use this [...]

Sorry, I exctracted the wrong part of one of my functions...
The code I pasted in my post above, calculates the angle (or the course you have to fly to reach latlong2 when you are at latlong2. The 'd' in the calculation is the angular distance.

Here's the right part for the distance in km:

Code:
d := 2 * arcsin(sqrt( sqr( sin((lat1-lat2)/2) ) + cos(lat1)*cos(lat2)*  sqr(sin((long1-long2)/2)) ));

d:= d * 180/pi;

Distance:= d * ( 2*pi*6370 / 360 );
Yes, this is the distance along a great circle as flytandem mentioned (shortest distance between 2 points over the surface of a sphere), where 6370 is the radius of earth (in km, so the result is in km as well).

regards,
mcduck

ps; nice to see other glider pilots here :)
and sorry for the Pascal/delphi language, but I think it's quite obvious to translate to c++..
 

agentgonzo

Grounded since '09
Addon Developer
Joined
Feb 8, 2008
Messages
1,649
Reaction score
4
Points
38
Location
Hampshire, UK
Website
orbiter.quorg.org
As the Earth is not a sphere (it's an oblate spheroid) the great-circle distance is not a perfect approximation. You can adjust for this, but it's still not perfect. It's probably good enough for what you're wanting to do, but if you want to be uber-accurate, then look up a paper published by Vincenty in 1975. I don't have the link unfortunately, but that was the best thing I could find when I was looking into this for work a few years ago. I have no idea how his algorithm works, but it is VERY accurate.
 

Scrooge McDuck

Addon Developer
Addon Developer
Joined
Mar 18, 2008
Messages
515
Reaction score
30
Points
28
Location
The Netherlands
Website
orbitermap.no-ip.org
As the Earth is not a sphere (it's an oblate spheroid) the great-circle distance is not a perfect approximation.

Yes a flattened sphere, or ellipsoidal model. Usually the WGS-84 model is used, you can find lots of information on this subject, with the keywords like wgs 84 distance Vincenty forward inverse formula.
For more accuracy using methods like these are indeed needed. It is iterative as there probably is no closed form to compute distances on an ellipsoid.
But still, these models (like the WGS-84 definition) have their limitations, as they are still a rough representation of the real shape of the Earth. The accuracy of WGS-84 is also not the same for different parts on Earth.

For example, here's a complete worked out script of this method:
http://www.movable-type.co.uk/scripts/latlong-vincenty.html


However, for computerex' application, this kind of accuracy is probably not needed.

regards,
mcduck
 
Top