Jump Calculations Jeff Zeitlin (27 Mar 2020 22:32 UTC)
Re: [TML] Jump Calculations Vareck Bostrom (28 Mar 2020 01:42 UTC)
Re: [TML] Jump Calculations Vareck Bostrom (28 Mar 2020 02:13 UTC)
Re: [TML] Jump Calculations Jeff Zeitlin (28 Mar 2020 19:16 UTC)
Re: [TML] Jump Calculations Vareck Bostrom (28 Mar 2020 19:26 UTC)
Re: [TML] Jump Calculations shadow@xxxxxx (28 Mar 2020 21:14 UTC)
Re: [TML] Jump Calculations Vareck Bostrom (28 Mar 2020 21:45 UTC)
Re: [TML] Jump Calculations Thomas RUX (29 Mar 2020 21:20 UTC)
Re: [TML] Jump Calculations Jeff Zeitlin (30 Mar 2020 22:13 UTC)
Re: [TML] Jump Calculations Thomas RUX (31 Mar 2020 02:37 UTC)
Re: [TML] Jump Calculations Kurt Feltenberger (31 Mar 2020 02:50 UTC)
Re: [TML] Jump Calculations Edward Anderson (31 Mar 2020 10:18 UTC)
Re: [TML] Jump Calculations Vareck Bostrom (31 Mar 2020 17:35 UTC)
Re: [TML] Jump Calculations Thomas RUX (31 Mar 2020 21:47 UTC)
Re: [TML] Jump Calculations Thomas RUX (31 Mar 2020 21:59 UTC)
Re: [TML] Jump Calculations Ewan (01 Apr 2020 13:04 UTC)
Re: [TML] Jump Calculations Thomas Jones-Low (13 Apr 2020 01:35 UTC)
Re: [TML] Jump Calculations kaladorn@xxxxxx (13 Apr 2020 02:49 UTC)
Plague Thomas RUX (31 Mar 2020 21:22 UTC)
Re: [TML] Plague Jeff Zeitlin (03 Apr 2020 10:23 UTC)
Re: [TML] Plague shadow@xxxxxx (03 Apr 2020 18:41 UTC)
Re: [TML] Plague Timothy Collinson (03 Apr 2020 19:42 UTC)
Re: [TML] Plague Timothy Collinson (03 Apr 2020 20:58 UTC)
Re: [TML] Plague Timothy Collinson (04 Apr 2020 07:01 UTC)
Re: [TML] Plague Thomas Jones-Low (05 Apr 2020 12:51 UTC)
Re: [TML] Plague Bruce Johnson (03 Apr 2020 20:40 UTC)
Re: [TML] Plague kaladorn@xxxxxx (13 Apr 2020 16:53 UTC)
Re: [TML] Plague Kenneth Barns (14 Apr 2020 01:07 UTC)
Re: [TML] Plague kaladorn@xxxxxx (14 Apr 2020 02:44 UTC)
Re: [TML] Plague Kenneth Barns (14 Apr 2020 08:08 UTC)
Re: [TML] Plague kaladorn@xxxxxx (15 Apr 2020 01:14 UTC)
Re: [TML] Plague shadow@xxxxxx (15 Apr 2020 01:13 UTC)
Re: [TML] Plague kaladorn@xxxxxx (15 Apr 2020 01:18 UTC)
Re: [TML] Plague Thomas RUX (15 Apr 2020 02:20 UTC)
Re: [TML] Jump Calculations Christopher Sean Hilton (12 Apr 2020 02:51 UTC)
Re: [TML] Jump Calculations Christopher Hilton (12 Apr 2020 12:00 UTC)
Re: [TML] Jump Calculations kaladorn@xxxxxx (12 Apr 2020 23:12 UTC)

Re: [TML] Jump Calculations Christopher Sean Hilton 12 Apr 2020 02:51 UTC

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)

        ## Calculate a third set of coordinates, (x, y, z)

        self.cube_x = self.alt_x
        self.cube_y = self.alt_y
        self.cube_z = -(self.cube_x + self.cube_y)

    def distance(self, other):
        """Calculate the distance between two hexes"""
        return max(abs(self.cube_x - other.cube_x),
                   abs(self.cube_y - other.cube_y),
                   abs(self.cube_z - other.cube_z))

def main():

    start = Hex(101)
    finish = Hex(801)

    distance = finish.distance(start)
    print("Distance: {}".format(distance))

```

Here's what the output looks like:

```
$ ipython
Python 3.7.6 (default, Dec 22 2019, 01:09:06)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: class Hex(o\bject):
   ...:
   ...:     def __init__(self, hex_label):
   ...:         self.hex_label = hex_label
[ ...snip... ]

In [2]: main()
Distance: 7
```

--
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]