Distance between two solar systems - Z value?

General discussion for players of Oolite.

Moderators: winston, another_commander

Post Reply
User avatar
pleiadian
Deadly
Deadly
Posts: 143
Joined: Mon Feb 20, 2017 2:14 pm

Distance between two solar systems - Z value?

Post by pleiadian »

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.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6682
Joined: Wed Feb 28, 2007 7:54 am

Re: Distance between two solar systems - Z value?

Post by another_commander »

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: https://bb.oolite.space/viewtopic.php?f=2&t=9642
User avatar
pleiadian
Deadly
Deadly
Posts: 143
Joined: Mon Feb 20, 2017 2:14 pm

Re: Distance between two solar systems - Z value?

Post by pleiadian »

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?
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Distance between two solar systems - Z value?

Post by cim »

pleiadian wrote: Mon Nov 20, 2017 3:16 pm
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
User avatar
hoqllnq
Commodore
Commodore
Posts: 154
Joined: Sun Jan 08, 2006 7:32 pm

Re: Distance between two solar systems - Z value?

Post by hoqllnq »

Code: Select all

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
User avatar
pleiadian
Deadly
Deadly
Posts: 143
Joined: Mon Feb 20, 2017 2:14 pm

Re: Distance between two solar systems - Z value?

Post by pleiadian »

Sometimes... looking at the keywords is kinda important. I feel stupid now. Thanks guys :)
Post Reply