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 rereading 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.
Distance between two solar systems  Z value?
Moderators: another_commander, winston

 Quite Grand SubAdmiral
 Posts: 5529
 Joined: Wed Feb 28, 2007 7:54 am
Re: Distance between two solar systems  Z value?
Without having looked at the code, I think the zvalue does not exist. What you see in that 3D map contains zvalues most likely selected specifically so that the the xy 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
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
Re: Distance between two solar systems  Z value?
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 xaxis every step is 0.4 LY, and on the yaxis 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?
However if you apply euclidean formulas and take into account that on the xaxis every step is 0.4 LY, and on the yaxis 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?
Re: Distance between two solar systems  Z value?
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
Re: Distance between two solar systems  Z value?
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;
}
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
Re: Distance between two solar systems  Z value?
Sometimes... looking at the keywords is kinda important. I feel stupid now. Thanks guys