[comp.sys.mac.games] Finding distances on map sheets

jtgorman@cs.arizona.edu (J. Taggart Gorman) (11/15/90)

   I have always wanted to code a few of my favorite war games on my
Mac, but the code for finding the distance between two hexes has always
eluded me.  I *want* hex maps, because that's what the games are played
on and I also feel that using squares does not represent life to well,
but then again, neither do hexes, really, but they're close enough for
me.
  Suggestions anyone?  Thanks in advance!

|     John Taggart Gorman Jr.    | "I'm a no rust build up man myself."
|                                |          -Christian Slater
| jtgorman@caslon.cs.arizona.edu |             in 'Heathers'

lins@Apple.COM (Chuck Lins) (11/16/90)

In article <532@caslon.cs.arizona.edu> jtgorman@cs.arizona.edu (J. Taggart Gorman) writes:
>
>   I have always wanted to code a few of my favorite war games on my
>Mac, but the code for finding the distance between two hexes has always
>eluded me.  I *want* hex maps, because that's what the games are played
>on and I also feel that using squares does not represent life to well,
>but then again, neither do hexes, really, but they're close enough for
>me.
>  Suggestions anyone?  Thanks in advance!

Back in the good ol' days when BYTE was a *real* computer mag :-) there was a
two part article on doing just that. Of course it was probably on some CP/M
machine long before the Mac even existed :-). I have the issues at home if
you really want the references just send mail and I'll look them up this
weekend.


-- 
Chuck Lins               | "Is this the kind of work you'd like to do?"
Apple Computer, Inc.     | -- Front 242
20525 Mariani Avenue     | Internet:  lins@apple.com
Mail Stop 37-BD          | AppleLink: LINS@applelink.apple.com
Cupertino, CA 95014      | "Self-proclaimed Object Oberon Evangelist"
The intersection of Apple's ideas and my ideas yields the empty set.

gordon@osiris.cso.uiuc.edu (John Gordon) (11/16/90)

	A while back in rec.games.programmer there was a discussion about 
hex map distance algorithms.  I saved the text of that thread, and if you want
I could post/email it.

gordon@osiris.cso.uiuc.edu (John Gordon) (11/17/90)

gordon@osiris.cso.uiuc.edu (John Gordon) writes:


>	A while back in rec.games.programmer there was a discussion about 
>hex map distance algorithms.  I saved the text of that thread, and if you want
>I could post/email it.

	Well, I've gotten several requests for this, so I'll post it. It will
be about Mon. or Tues. before I can do it, because I've gotta find the disks
that it's on :-).

---
John Gordon
Internet: gordon@osiris.cso.uiuc.edu        #include <disclaimer.h>
          gordon@cerl.cecer.army.mil       #include <clever_saying.h>
GEnie:    j.gordon14                  

wolf@alesi.cipl.uiowa.edu (Mike Wolf) (11/17/90)

I don't see any trick here. When using hex or squares or what not.
The distanc you want is most likely from the center of you sector 
unit, correct?  Why would you want to take the distance from one 
side of a hex to another, that would be just like going from the
center of the first one to the center of the second hex.

Anyway....simple math will give you the width of your hex, from
opposing sides (not vertices mind you).

In your code for finding the distance you could use the starting
pixel point and the end pixel point to find your dX and dY.

From the width of the hex you got you can tell how many pixels it
took to cross that width, then you can scale this to what ever
your map is and use some simple algebra to get the distance
between the pixels (just find the length of the hypotenuse of the
triangle created with your two points).

If you cannot follow me very well, let me know and I will whip
up some simple sample code (given that you tell me what you are
exactly wanting and trying to do)

Michael

Reply to WOLF@MEL.CIPL.UIOWA.EDU