On Apr 11, 2020, at 10:51 PM, Christopher Sean Hilton <xxxxxx@vindaloo.com> wrote:
>
> On Fri, Mar 27, 2020 at 06:32:37PM -0400, Jeff Zeitlin wrote:
>> Given a standard Traveller subsector, with coordinates 0101 to 0810,
>> alternate columns staggered, what's the formula/algorithm to calculate the
>> jump distance between two hexes?
>>
>
> To start, there is a wealth of information on hex grids here:
>
> * [Hexagonal Grids](https://www.redblobgames.com/grids/hexagons/)
>
> Your question is best answered by the sections on Coordinate systems
> and distances:
>
> * [Hex Coordinate systems](https://www.redblobgames.com/grids/hexagons/#coordinates)
> * [Hex Distances](https://www.redblobgames.com/grids/hexagons/#distances)
>
> ----------------------------------------
>
> If you read the sections it will give you the algorithm. Here's some
> python that implements it.
>
> ```
> class Hex(object):
>
> def __init__(self, hex_label):
> self.hex_label = hex_label
>
> ## Break a four digit hex label into it's x and y components
>
> self.x, self.y = divmod(hex_label, 100)
>
> ## Calculate an alternate (x, y) in this system two hexes
> ## with the same y value will always be in a row.
>
> self.alt_x = self.x
> self.alt_y = self.y - (self.x // 2)
>
There’s a of-by-one bug here: The above line should read:
`self.alt_y = self.y - ((self.x - 1) // 2)`
[ …snip… ]
Chris
__o "All I was trying to do was get home from work."
_`\<,_ -Rosa Parks
___(*)/_(*)____.___o____..___..o...________ooO..._____________________
Christopher Sean Hilton [chris/at/vindaloo/dot/com]
-----
The Traveller Mailing List
Archives at http://archives.simplelists.com/tml
Report problems to xxxxxx@simplelists.com
To unsubscribe from this list please go to
http://www.simplelists.com/confirm.php?u=RDHE7iRpfwqlHvVvWBIhpJZsbTiD5NnL