Page 1 of 1
Light year distance calculation
Posted: Mon Jan 12, 2015 6:59 am
by phkb
What's the correct way of calculating the distance in LY between two systems? I know I can do this using Javascript, but if I were doing it outside the system, using two sets of co-ordinates, the standard geometric function SQRT((X2-X1)^2 + (Y2-Y1)^2) doesn't seem to match the actual distances in game.
Also, on the Wiki, for the New Galaxy Guide, there's a clickable sector map, and in the Wiki code page it has entries like this for each planet:
Code: Select all
{{ClickMapEntry|Name=Tibedied|Sector=1|XPos=2|YPos=90|XPosRel=7|YPosRel=136}}
.What are the XPosRel and YPosRel values and how do they relate to the XPos and YPos values.
Re: Light year distance calculation
Posted: Mon Jan 12, 2015 7:22 am
by cim
phkb wrote:the standard geometric function SQRT((X2-X1)^2 + (Y2-Y1)^2) doesn't seem to match the actual distances in game.
There are two things that stop this working.
- Both coordinates are measured 0-255, but the Y-coordinate describes half the distance
- For compatibility with Elite, the calculation uses integer maths to calculate in units of 0.4 LY
Here's a JS version of the formula.
Code: Select all
var dx = x1 - x2;
var dy = Math.floor((y1 - y2)/2);
return (Math.floor(Math.sqrt((dx*dx)+(dy*dy)))*0.4);
The XPosRel and YPosRel coordinates appear to have been normalised to put both X and Y into the same units, which I suspect - without checking - is "pixels on the map on the Wiki".
Re: Light year distance calculation
Posted: Mon Jan 12, 2015 7:43 am
by phkb
Thanks, cim!
Re: Light year distance calculation
Posted: Mon Nov 01, 2021 11:48 pm
by Cholmondely
cim wrote: ↑Mon Jan 12, 2015 7:22 am
phkb wrote:the standard geometric function SQRT((X2-X1)^2 + (Y2-Y1)^2) doesn't seem to match the actual distances in game.
There are two things that stop this working.
- Both coordinates are measured 0-255, but the Y-coordinate describes half the distance
- For compatibility with Elite, the calculation uses integer maths to calculate in units of 0.4 LY
Here's a JS version of the formula.
Code: Select all
var dx = x1 - x2;
var dy = Math.floor((y1 - y2)/2);
return (Math.floor(Math.sqrt((dx*dx)+(dy*dy)))*0.4);
The XPosRel and YPosRel coordinates appear to have been normalised to put both X and Y into the same units, which I suspect - without checking - is "pixels on the map on the Wiki".
Can anybody help with this, please?
Cody & I want to finish off this page and get it up on the wiki.
Code: Select all
== Map ==
[[Sector7/The Ceraso Hub (Region)|The Ceraso Hub]] consists of the systems [[Sector7/Anisinza|Anisinza]], [[Sector7/Ceraso|Ceraso]], [[Sector7/Ceerti|Ceerti]] and [[Sector7/Gebeti|Gebeti]].
This is the problematic bit: how on earth do I calculate the XPosRel & YPosRel values?
Code: Select all
<div style="position:relative">{{ClickMapHeader|Sector=7|Image=Sector7_The_Ceraso_Hub_RegionMap.png}}
{{ClickMapEntry|Name=Anisinza|Sector=7|XPos=19|YPos=14|XPosRel=???|YPosRel=??}}
{{ClickMapEntry|Name=Ceraso|Sector=7|XPos=13|YPos=1|XPosRel=???|YPosRel=??}}
{{ClickMapEntry|Name=Ceerti|Sector=7|XPos=1|YPos=9|XPosRel=???|YPosRel=??}}
{{ClickMapEntry|Name=Gebeti|Sector=7|XPos=0|YPos=15|XPosRel=???|YPosRel=??}}
{{ClickMapFooter}}</div>
Code: Select all
{{SectorTableHeader}}
{{SectorTableEntry|Name=Anisinza|Sector=7|System=90|XPos=19|YPos=14|Government=3|Economy=6|Techlevel=7|Population=3.4|Inhabitants=Human Colonists|Productivity=7616|Hubcount=2|Description=The world Anisinza is scourged by deadly disease.}}
{{SectorTableEntry|Name=Ceraso|Sector=7|System=113|XPos=13|YPos=1|Government=5|Economy=1|Techlevel=11|Population=4.7|Inhabitants=Fierce Yellow Fat Humanoids|Productivity=30456|Hubcount=3|Description=The planet Ceraso is reasonably fabled for its exciting sit coms and its inhabitants' exceptional love for food blenders.}}
{{SectorTableEntry|Name=Ceerti|Sector=7|System=62|XPos=1|YPos=9|Government=1|Economy=3|Techlevel=7|Population=3.5|Inhabitants=Fierce Slimy Frogs|Productivity=8120|Hubcount=2|Description=This world is a revolting little planet.}}
{{SectorTableEntry|Name=Gebeti|Sector=7|System=126|XPos=0|YPos=15|Government=1|Economy=7|Techlevel=2|Population=1.3|Inhabitants=Large Green Lizards|Productivity=1560|Hubcount=2|Description=Gebeti is very fabled for its ancient Gebetian Et banana plantations.}}
{{SectorTableFooter}}
[[Category:Sector7/Region|The Ceraso Hub]]
{{RoutesAndRegionsSector7}}
Re: Light year distance calculation
Posted: Wed Jan 05, 2022 12:46 pm
by Cody
Re: Light year distance calculation
Posted: Wed Jan 05, 2022 1:26 pm
by hiran
Cholmondely wrote: ↑Mon Nov 01, 2021 11:48 pm
Can anybody help with this, please?
Cody & I want to finish off this page and get it up on the wiki.
Code: Select all
== Map ==
[[Sector7/The Ceraso Hub (Region)|The Ceraso Hub]] consists of the systems [[Sector7/Anisinza|Anisinza]], [[Sector7/Ceraso|Ceraso]], [[Sector7/Ceerti|Ceerti]] and [[Sector7/Gebeti|Gebeti]].
This is the problematic bit: how on earth do I calculate the XPosRel & YPosRel values?
Code: Select all
<div style="position:relative">{{ClickMapHeader|Sector=7|Image=Sector7_The_Ceraso_Hub_RegionMap.png}}
{{ClickMapEntry|Name=Anisinza|Sector=7|XPos=19|YPos=14|XPosRel=???|YPosRel=??}}
{{ClickMapEntry|Name=Ceraso|Sector=7|XPos=13|YPos=1|XPosRel=???|YPosRel=??}}
{{ClickMapEntry|Name=Ceerti|Sector=7|XPos=1|YPos=9|XPosRel=???|YPosRel=??}}
{{ClickMapEntry|Name=Gebeti|Sector=7|XPos=0|YPos=15|XPosRel=???|YPosRel=??}}
{{ClickMapFooter}}</div>
[/code]
I guess what you are after is ultimately an
HTML Image Map.
However, as people think HTML is too complicated Wiki applications were created that allow simple text editing and they automatically translate to HTML. Over time they needed more power, and one by one a lot of HTML features became accessible via Wikis - but they still tend to translate.
So you need to learn how to create an Image Map in MediaWiki. Unfortunately I cannot find any documentation for MediaWiki and ClickMapEntry or other such keywords. However MediaWiki documentation would be the authorative source, unless it comes from a plugin that was installed on top.
There is a chance that these values are not used at all. When I checked one of these maps, it seems all ClickMapEntries get intermingled into rectangular areas five pixels high and five pixels wide.
Re: Light year distance calculation
Posted: Tue Feb 22, 2022 6:43 am
by PhantorGorth
Cholmondely wrote: ↑Mon Nov 01, 2021 11:48 pm
cim wrote: ↑Mon Jan 12, 2015 7:22 am
phkb wrote:the standard geometric function SQRT((X2-X1)^2 + (Y2-Y1)^2) doesn't seem to match the actual distances in game.
There are two things that stop this working.
- Both coordinates are measured 0-255, but the Y-coordinate describes half the distance
- For compatibility with Elite, the calculation uses integer maths to calculate in units of 0.4 LY
Here's a JS version of the formula.
Code: Select all
var dx = x1 - x2;
var dy = Math.floor((y1 - y2)/2);
return (Math.floor(Math.sqrt((dx*dx)+(dy*dy)))*0.4);
The XPosRel and YPosRel coordinates appear to have been normalised to put both X and Y into the same units, which I suspect - without checking - is "pixels on the map on the Wiki".
Can anybody help with this, please?
Cody & I want to finish off this page and get it up on the wiki.
Code: Select all
== Map ==
[[Sector7/The Ceraso Hub (Region)|The Ceraso Hub]] consists of the systems [[Sector7/Anisinza|Anisinza]], [[Sector7/Ceraso|Ceraso]], [[Sector7/Ceerti|Ceerti]] and [[Sector7/Gebeti|Gebeti]].
This is the problematic bit: how on earth do I calculate the XPosRel & YPosRel values?
Code: Select all
<div style="position:relative">{{ClickMapHeader|Sector=7|Image=Sector7_The_Ceraso_Hub_RegionMap.png}}
{{ClickMapEntry|Name=Anisinza|Sector=7|XPos=19|YPos=14|XPosRel=???|YPosRel=??}}
{{ClickMapEntry|Name=Ceraso|Sector=7|XPos=13|YPos=1|XPosRel=???|YPosRel=??}}
{{ClickMapEntry|Name=Ceerti|Sector=7|XPos=1|YPos=9|XPosRel=???|YPosRel=??}}
{{ClickMapEntry|Name=Gebeti|Sector=7|XPos=0|YPos=15|XPosRel=???|YPosRel=??}}
{{ClickMapFooter}}</div>
Code: Select all
{{SectorTableHeader}}
{{SectorTableEntry|Name=Anisinza|Sector=7|System=90|XPos=19|YPos=14|Government=3|Economy=6|Techlevel=7|Population=3.4|Inhabitants=Human Colonists|Productivity=7616|Hubcount=2|Description=The world Anisinza is scourged by deadly disease.}}
{{SectorTableEntry|Name=Ceraso|Sector=7|System=113|XPos=13|YPos=1|Government=5|Economy=1|Techlevel=11|Population=4.7|Inhabitants=Fierce Yellow Fat Humanoids|Productivity=30456|Hubcount=3|Description=The planet Ceraso is reasonably fabled for its exciting sit coms and its inhabitants' exceptional love for food blenders.}}
{{SectorTableEntry|Name=Ceerti|Sector=7|System=62|XPos=1|YPos=9|Government=1|Economy=3|Techlevel=7|Population=3.5|Inhabitants=Fierce Slimy Frogs|Productivity=8120|Hubcount=2|Description=This world is a revolting little planet.}}
{{SectorTableEntry|Name=Gebeti|Sector=7|System=126|XPos=0|YPos=15|Government=1|Economy=7|Techlevel=2|Population=1.3|Inhabitants=Large Green Lizards|Productivity=1560|Hubcount=2|Description=Gebeti is very fabled for its ancient Gebetian Et banana plantations.}}
{{SectorTableFooter}}
[[Category:Sector7/Region|The Ceraso Hub]]
{{RoutesAndRegionsSector7}}
I have figured out how it works.
The image of the map has margins that it needs to make sure no star system is too close to the edge of the map. The click test image image on
https://wiki.alioth.net/index.php/User:Treczoks is 774px x 390px (
width x
height). So assuming an even margin all the way round the margin value m must follow the equation (774 - 2m)/(390 - 2m) = 2 which gives a value of m = 3px. (If you are wondering why it equals 2, that is because the galaxy maps are 2 x 1 in shape.)
So there is an
left-margin and
top-margin for the image to the (0, 0) co-ordinate. 3px for both in this case. There would also be a
right-margin and
bottom-margin both 3px too.
By inspecting the page the clickable points are overlaid divs with dimensions 5px x 5px. So lets call this box to have
box-width and
box-height both equal to 5px in this case.
Taking the above into account and that the Y-axis is half the scale of the x-axis. Both co-ordinates for (
XPos and
YPos for the systems) range 0 to 256 each (therefore
horizontal-range and
vertical-range equal 256 each) from top left of the map then:
Code: Select all
XPosRel = XPos / horizontal-range * (width - left-margin - right-margin) + left-margin - ((box-width - 1) / 2)
YPosRel = YPos / vertical-range * (height - top-margin - bottom-margin) + top-margin - ((box-height - 1) / 2)
Given that the
XPosRel and
YPosRel are both integers in the examples on that page you may need to to round those calculated value to the nearest integer.
Looking at the image Cemave at the top has a YPos of 0 is at the fifth pixel from the top not 3 and Laeden at the bottom has a YPos of 254 and is at the fifth pixel from the bottom of the image. So It looks like the map has been shifted 2 pixels down to centre it vertically. There is likely to be a horizontal centring going on too so you would need to adjust the map width and height ranges (the horizontal-range and vertical-range) and margins accordingly. Please note that the values of XPosRel and YPosRel used by the page are not quite centred on the systems but as long as you get the ranges and margins correct my formulae above should work.
Phantor Gorth
Re: Light year distance calculation
Posted: Tue Jun 28, 2022 1:58 pm
by Cholmondely
PhantorGorth wrote: ↑Tue Feb 22, 2022 6:43 am
Cholmondely wrote: ↑Mon Nov 01, 2021 11:48 pm
Can anybody help with this, please?
Cody & I want to finish off this page and get it up on the wiki.
Code: Select all
== Map ==
[[Sector7/The Ceraso Hub (Region)|The Ceraso Hub]] consists of the systems [[Sector7/Anisinza|Anisinza]], [[Sector7/Ceraso|Ceraso]], [[Sector7/Ceerti|Ceerti]] and [[Sector7/Gebeti|Gebeti]].
This is the problematic bit: how on earth do I calculate the XPosRel & YPosRel values?
Code: Select all
<div style="position:relative">{{ClickMapHeader|Sector=7|Image=Sector7_The_Ceraso_Hub_RegionMap.png}}
{{ClickMapEntry|Name=Anisinza|Sector=7|XPos=19|YPos=14|XPosRel=???|YPosRel=??}}
{{ClickMapEntry|Name=Ceraso|Sector=7|XPos=13|YPos=1|XPosRel=???|YPosRel=??}}
{{ClickMapEntry|Name=Ceerti|Sector=7|XPos=1|YPos=9|XPosRel=???|YPosRel=??}}
{{ClickMapEntry|Name=Gebeti|Sector=7|XPos=0|YPos=15|XPosRel=???|YPosRel=??}}
{{ClickMapFooter}}</div>
I have figured out how it works.
The image of the map has margins that it needs to make sure no star system is too close to the edge of the map. The click test image image on
https://wiki.alioth.net/index.php/User:Treczoks is 774px x 390px (
width x
height). So assuming an even margin all the way round the margin value m must follow the equation (774 - 2m)/(390 - 2m) = 2 which gives a value of m = 3px. (If you are wondering why it equals 2, that is because the galaxy maps are 2 x 1 in shape.)
So there is an
left-margin and
top-margin for the image to the (0, 0) co-ordinate. 3px for both in this case. There would also be a
right-margin and
bottom-margin both 3px too.
By inspecting the page the clickable points are overlaid divs with dimensions 5px x 5px. So lets call this box to have
box-width and
box-height both equal to 5px in this case.
Taking the above into account and that the Y-axis is half the scale of the x-axis. Both co-ordinates for (
XPos and
YPos for the systems) range 0 to 256 each (therefore
horizontal-range and
vertical-range equal 256 each) from top left of the map then:
Code: Select all
XPosRel = XPos / horizontal-range * (width - left-margin - right-margin) + left-margin - ((box-width - 1) / 2)
YPosRel = YPos / vertical-range * (height - top-margin - bottom-margin) + top-margin - ((box-height - 1) / 2)
Given that the
XPosRel and
YPosRel are both integers in the examples on that page you may need to to round those calculated value to the nearest integer.
Looking at the image Cemave at the top has a YPos of 0 is at the fifth pixel from the top not 3 and Laeden at the bottom has a YPos of 254 and is at the fifth pixel from the bottom of the image. So It looks like the map has been shifted 2 pixels down to centre it vertically. There is likely to be a horizontal centring going on too so you would need to adjust the map width and height ranges (the horizontal-range and vertical-range) and margins accordingly. Please note that the values of XPosRel and YPosRel used by the page are not quite centred on the systems but as long as you get the ranges and margins correct my formulae above should work.
Phantor Gorth
Alas, while I think I vaguely comprehend what you are doing (margins,
et al) I've no idea as to how to use it (we non-programmers...).
By the way, I've put up a
wiki user-page for you to mangle as you see fit.
Re: Light year distance calculation
Posted: Tue Jun 28, 2022 9:48 pm
by Switeck
Re: Light year distance calculation
Posted: Tue Jun 28, 2022 10:01 pm
by Switeck
The 1st link:
viewtopic.php?f=2&t=9729
...has the best formula examples for both distances and times.
Up to you to mention the others or not...even this thread.
Re: Light year distance calculation
Posted: Wed Jun 29, 2022 11:50 am
by Cody
Switeck wrote: ↑Tue Jun 28, 2022 9:48 pmAnd even weirder edge cases when dealing with misjumps:
You don't say!
Re: Light year distance calculation
Posted: Thu Apr 20, 2023 9:11 pm
by Cholmondely
Cody wrote: ↑Wed Jun 29, 2022 11:50 am
Have you seen? Alnivel fixed our problems with the regional map for the
Lizard's Claw!