Oolite Bulletins

For information and discussion about Oolite.
It is currently Mon Dec 11, 2017 9:46 am

All times are UTC




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Fri Nov 17, 2017 12:56 pm 
Online
Dangerous
Dangerous
User avatar

Joined: Mon Feb 20, 2017 2:14 pm
Posts: 123
Maybe this one's for the dev's and I'm hitting a wall here. I'm trying to create really funky tool having to do with the solar systems of Oolite. For that to work, I need to be able to determine the distance between two systems. Whatever approach I took, the result was incorrect (I do know the formula to calculate distances though).

I then stumbled upon this older tool: http://www.pcooper.net/oolite/OoliteInteractiveMap.html

If you enable "3D" on the right and hover over any system, you can see a third position - the Z value - for the position of the system in space (everything else I have is correct). And that's really interesting, because planetinfo.plist only provides 2D coordinates for every system.

Can one of the dev's tell me where this little funky value for each solar system is hiding? Scanning the GitHub repo for it, and carefully re-reading planetinfo.plist did not help. If I knew where to find that, I can do proper distance calculations and hopefully provide you with something real slick.

_________________
DeeperSpace HUD | pleiadian's Oolite GitHub


Top
   
PostPosted: Fri Nov 17, 2017 1:49 pm 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral

Joined: Wed Feb 28, 2007 7:54 am
Posts: 5023
Without having looked at the code, I think the z-value does not exist. What you see in that 3D map contains z-values most likely selected specifically so that the the x-y distances between systems do not get modified too excessively. I believe you will find that not all distances in that 3D map are exactly the same as the "official" ones.

This is a subject that was discussed some years ago, here is a relevant thread about it: http://www.aegidian.org/bb/viewtopic.php?f=2&t=9642


Top
   
PostPosted: Mon Nov 20, 2017 3:16 pm 
Online
Dangerous
Dangerous
User avatar

Joined: Mon Feb 20, 2017 2:14 pm
Posts: 123
OK I'm really a bit flabbergasted. I looked through the entire Oolite source code to determine the function that calculates distances between two systems. To be sure I get it right, I took the example of Lave <-> Leesti, which is 3.6 LY - according to the game.

However if you apply euclidean formulas and take into account that on the x-axis every step is 0.4 LY, and on the y-axis you have 0.2 LY, you get out a distance of 3.9 LY.

And here's the kicker... apparently even Oolite itself thinks it's 3.9 LY. I found the code that does it:

https://github.com/OoliteProject/oolite ... dom.h#L166

I found the reference to the function first in this line, which is - I think - responsible to draw the map in the F6 screen:
https://github.com/OoliteProject/oolite ... en.m#L1899

I wrote a small tool in PHP, adapted the formula as found in above GitHub gem... and it's exactly 3.9597979746447 LY according to PHP, using that very same algorithm. I used my own formula before, and I got the same result.

So now comes the obvious question...

How does Oolite calculate the distance between two systems?

_________________
DeeperSpace HUD | pleiadian's Oolite GitHub


Top
   
PostPosted: Mon Nov 20, 2017 3:42 pm 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
User avatar

Joined: Fri Nov 11, 2011 6:19 pm
Posts: 4015
Quote:
How does Oolite calculate the distance between two systems?
The bit you're missing is the int dist on the sqrt function (Line 173)

So you do the sqrt and you get ~9.8975

This then gets cast to an integer, which rounds it down to 9. And then, 0.4 * 9 = 3.6 LY

_________________
OXPs: [EliteWiki] New Cargoes, [EliteWiki] Skilled NPCs, [EliteWiki] Curse of the Black Sunspot, and more


Top
   
PostPosted: Mon Nov 20, 2017 3:53 pm 
Offline
Commodore
Commodore
User avatar

Joined: Sun Jan 08, 2006 7:32 pm
Posts: 148
Code:
OOINLINE double distanceBetweenPlanetPositions(int x1, int y1, int x2, int y2)
{
	int dx = x1 - x2;
	int dy = (y1 - y2)/2;
	int dist = sqrt(dx*dx + dy*dy);	// N.b. Rounding error due to truncation is desired.
	return 0.4 * dist;
}
Note that everything except the return value is in ints.

Lave: 20, 173
Leesti: 13, 186

dx = 20 - 13 = 7
dy = (186 - 173) / 2 = 6 <-- Rounding error due to truncation is desired

7 * 7 + 6 * 6 = 85

sqrt(85) = 9 <-- Rounding error due to truncation is desired

9 * 0.4 = 3.6


Top
   
PostPosted: Tue Nov 21, 2017 7:57 am 
Online
Dangerous
Dangerous
User avatar

Joined: Mon Feb 20, 2017 2:14 pm
Posts: 123
Sometimes... looking at the keywords is kinda important. I feel stupid now. Thanks guys :)

_________________
DeeperSpace HUD | pleiadian's Oolite GitHub


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Limited