Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Calculating distance using hex coordinate system
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
m...@nowhere.edu  
View profile  
 More options Sep 14 2007, 10:46 pm
Newsgroups: rec.games.design
From: m...@nowhere.edu
Date: Sat, 15 Sep 2007 02:46:45 GMT
Local: Fri, Sep 14 2007 10:46 pm
Subject: Calculating distance using hex coordinate system
Howdy all,

I've created a hex grid bitmap, and have assigned each hex a
coordinate exactly as portrayed on this page,
http://www.gamedev.net/reference/articles/article1800.asp and am now
trying to nail down the algorithm to determine the distance between
any two hexes when the coordinates are known.

it seems like it should be easy, but damn if I just can't reason it
out!

Any suggestions would be appreciated. I am coding in c#.net but I
should be able to  translate from almost any programming language, so
don't let that be a barrier to you in posting. =)

Thanx


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christopher Dearlove  
View profile  
 More options Sep 15 2007, 9:50 am
Newsgroups: rec.games.design
From: Christopher Dearlove <ch...@mnemosyne.demon.co.uk>
Date: Sat, 15 Sep 2007 14:50:49 +0100
Local: Sat, Sep 15 2007 9:50 am
Subject: Re: Calculating distance using hex coordinate system
In message <cihme3tl3b7knounivjrfhksoi6shn4...@4ax.com>, m...@nowhere.edu
writes

>Any suggestions would be appreciated. I am coding in c#.net but I
>should be able to  translate from almost any programming language, so
>don't let that be a barrier to you in posting. =)

As I recall - I had a non-games reason for it once - if the shortest
path
from the centre of one hex to another is m hexes along one row, then
n hexes along another (so that most games measure the distance as
m+n) then the actual distance is

sqrt(m^2 + mn + n^2) or sqrt([m+n]^2 - mn)

assuming the distance from the centre of one hex to the next is 1
(otherwise multiply by it).

It was a few years ago, and I haven't checked it today. But I'm
reasonably confident of it.

(This comes up in ideal cellular radio systems. This maps to
reusing m^2 + mn + n^2 frequencies, and only some numbers
work: 1, 3, 4, 7, 9, ...)

--
Christopher Dearlove


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nick Wedd  
View profile  
 More options Sep 15 2007, 9:52 am
Newsgroups: rec.games.design
From: Nick Wedd <n...@maproom.co.uk>
Date: Sat, 15 Sep 2007 14:52:21 +0100
Local: Sat, Sep 15 2007 9:52 am
Subject: Re: Calculating distance using hex coordinate system
In message <cihme3tl3b7knounivjrfhksoi6shn4...@4ax.com>, m...@nowhere.edu
writes

>Howdy all,

>I've created a hex grid bitmap, and have assigned each hex a
>coordinate exactly as portrayed on this page,
>http://www.gamedev.net/reference/articles/article1800.asp and am now
>trying to nail down the algorithm to determine the distance between
>any two hexes when the coordinates are known.

What kind of distance do you want to calculate?  The two most likely
possibilities are
1.)  The hex equivalent of "Manhattan distance", i.e. the number of
"king's moves" it takes to get from one hex to another
2.)  The Euclidean distance between the centres of two hexes

Nick

>it seems like it should be easy, but damn if I just can't reason it
>out!

>Any suggestions would be appreciated. I am coding in c#.net but I
>should be able to  translate from almost any programming language, so
>don't let that be a barrier to you in posting. =)

>Thanx

--
Nick Wedd    n...@maproom.co.uk

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christopher Dearlove  
View profile  
 More options Sep 15 2007, 11:09 am
Newsgroups: rec.games.design
From: Christopher Dearlove <ch...@mnemosyne.demon.co.uk>
Date: Sat, 15 Sep 2007 16:09:17 +0100
Local: Sat, Sep 15 2007 11:09 am
Subject: Re: Calculating distance using hex coordinate system
In message <fSGV$asVO+6GF...@maproom.demon.co.uk>, Nick Wedd
<n...@maproom.co.uk> writes

>What kind of distance do you want to calculate?  The two most likely
>possibilities are
>1.)  The hex equivalent of "Manhattan distance", i.e. the number of
>"king's moves" it takes to get from one hex to another
>2.)  The Euclidean distance between the centres of two hexes

In terms of my answer, 1) is m+n, 2) is (I believe, note caveats) given
by the formula I gave. [And the background I gave probably tells you
what you could Google for - there's probably a Wikipedia article
covering it, I haven't checked.]

--
Christopher Dearlove


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
m...@nowhere.edu  
View profile  
 More options Sep 16 2007, 2:58 pm
Newsgroups: rec.games.design
From: m...@nowhere.edu
Date: Sun, 16 Sep 2007 18:58:20 GMT
Local: Sun, Sep 16 2007 2:58 pm
Subject: Re: Calculating distance using hex coordinate system
On Sat, 15 Sep 2007 14:52:21 +0100, Nick Wedd <n...@maproom.co.uk>
wrote:

Distance as measured in the smallest number of hexes that would have
to be crossed to get from the first hex to the second.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Torben Ægidius Mogensen  
View profile  
 More options Sep 17 2007, 6:15 am
Newsgroups: rec.games.design
From: torb...@app-1.diku.dk (Torben Ægidius Mogensen)
Date: Mon, 17 Sep 2007 12:15:24 +0200
Local: Mon, Sep 17 2007 6:15 am
Subject: Re: Calculating distance using hex coordinate system

m...@nowhere.edu writes:
> Howdy all,

> I've created a hex grid bitmap, and have assigned each hex a
> coordinate exactly as portrayed on this page,
> http://www.gamedev.net/reference/articles/article1800.asp and am now
> trying to nail down the algorithm to determine the distance between
> any two hexes when the coordinates are known.

I prefer a numbering where both x and y correspond to straight lines
of hexes, i.e., letting x increase (with constant y) by going right
and y increase (with constant x) by going 60 degrees down from right
(assuming (0,0) is top left corner).

This way, if you move in one of the three "natural" directions, you
either have constant x, constant y or constant (x+y).

That makes calculation of distances etc. easier, as you don't have to
sepcial-case on odd and even rows.

I assume you know the hex coordinates and want to find the distance in
number of hexes while moving across edges.

If you had used the alternative numbering I described above, the
distance is calculated as follows:

mydistance((x1,y1), (x2,y2))
 = if x1>x2 then mydistance((x2,y2), (x1,y1))
   else if y2>=y1 then x2-x1 + y2-y1
   else max(x2-x1, y1-y2)

With the numbering shown on the webpage you sited, you can calculate
distance as follows:

yourdistance((x1,y1),(x2,y2))
 = mydistance((x1 - y1 `div` 2,y1), (x2 - y2 `div` 2,y2))

I.e., convert to the simpler coordinate system and calculate distance
in that.  You convert by subtracting half the y coordinate (rounded
down) from the x coordinate.

        Torben


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefano MAC:GREGOR  
View profile  
 More options Sep 17 2007, 11:52 am
Newsgroups: rec.games.design
From: "Stefano MAC:GREGOR" <esperant...@yahoo.com>
Date: Mon, 17 Sep 2007 08:52:11 -0700
Local: Mon, Sep 17 2007 11:52 am
Subject: Re: Calculating distance using hex coordinate system
m...@nowhere.edu skribis:

> I've created a hex grid bitmap, and have assigned each hex a
> coordinate exactly as portrayed on this page,
> http://www.gamedev.net/reference/articles/article1800.asp and am now
> trying to nail down the algorithm to determine the distance between
> any two hexes when the coordinates are known.

I worked this out a few decades ago, and I believe my answer was even
published in some gaming magazine - one of SPI's, as I recall.

To make it easier, I had non-staggering coördinates, so that with
coördinates of [x,y], all hexes with the same value of "y" were in the
same horizontal row, and all with the same value of "x" were in the
same diagonal row.

[0,0]     [0,1]     [0,2]     [0,3]     [0,4]     [0,5]
     [1,1]     [1,2}     [1,3]     [1,4]     [1,5]     [1,6]
[2,1]     [2,2]     [2,3]     [2,4]     [2,5]     [2,6]
     [3,2]     [3,3]     [3,4]     [3,5]     [3,6]     [3,7]
[4,2]     [4,3]     [4,4]     [4,5]     [4,6]     [4,7]
     [5,3]     [5,4]     [5,5]     [5,6]     [5,7]     [5,6]

Now to calculate the hex-distance between two hexes, calculate the
difference between their x-coördinates, the difference between their y-
coördinates, and the difference between these two differences; take
the absolute value of each of these three numbers, and the distance is
the largest of these three values.

So -- for the distrance from [5,5] to [3,6],  x = -2,  y = 1, and the
difference between the two deltas is 3.  The greatest of 2, 1, and 3
is three, and Bob's your uncle.

--
Steve
299,792,358 m/s -- it's not just a good idea; it's the LAW!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
m...@nowhere.edu  
View profile  
 More options Sep 17 2007, 4:46 pm
Newsgroups: rec.games.design
From: m...@nowhere.edu
Date: Mon, 17 Sep 2007 20:46:41 GMT
Local: Mon, Sep 17 2007 4:46 pm
Subject: Re: Calculating distance using hex coordinate system
Torben, that did the trick! Thank you very much for your assistance!

On Mon, 17 Sep 2007 12:15:24 +0200, torb...@app-1.diku.dk (Torben


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »