Issue with Hex Map

Tryin to draw my temp hex tiles, but i am having problems getting them to ‘stick’ horizontially, ive read tuts. but my problem is that i dont know how to find the length of each side on the hexagon, i need that for the other problems to work, but ive gone this far with just dividing the rectangular hexagon image.

code:

// even row
if (i%2==0) {
hexGraphic[i][j].draw(g,
(int)xPos+i*HEX_SIZE,
(int)yPos+j*HEX_SIZE);
}
// odd row
else {
hexGraphic[i][j].draw(g,
(int)xPos+i*HEX_SIZE,
(int)yPos+j*HEX_SIZE+HEX_SIZE/2);
}

picture:
http://img295.imageshack.us/img295/8981/hexhelpni9.png

See the hexagon as a circle with 6 points on it.

Calculate the coordinates of 2 points next to eachother.

Calculate the distance between the coordinates.

http://www.gamedev.net/reference/articles/article1800.asp

Just keep in mind that a hexagon is basically a diamond (or an isometric square) with a square shoved into the middle.

I was using that same exact tutorial, but the problem lies in that, I want my program to figure out ‘s’ the length of each side on the hexagon, for ANY size hexagon as I please and that i passed from a constructor. I have been hearing many ways to do it, pretend it a circle, a triangle,n or a diamond, lol. I’ll see what I can do, but im an idiot noob after all.

also a general question about hex maps, are they more wide than they are tall? Because i was looking at some hexes and they seem wider than my 80x80 hex. Kinda making me furious!

EDIT: i found out in photoshop while making a hexagon, that its wider than tall. Its more attractive this way, but now my calculations have been destroyed.

So what you want is the length of the hexagon’s sides when the hexagon is in a certain size square (e.g. when it’s replacing a tile).

Going by the article:

“a” would be the width of the tile
“b” would be the height of the tile

Use these 2 equations:

b = s + 2 * h
h = sin(30) * s

Since sin(30) = 0.5,

h = s / 2

Combining that with the equation for b, we get

b = s + 2 * s / 2 = b = 2 * s

So s = b / 2.

This means that the length of each side is equal to half the height of the square tile.

Since r = cos(30) * s and cos(30) is approximately 0.866, a should be a little bit less than b.

I found another article at http://www.gamedev.net/reference/articles/article747.asp , which might be useful.

I figured it out actually, i did it by just multiplying the [i] positions by HEX_SIZE*0.75, and it figures out the overlap, and everything works great now. Thanks guys.

HEX_SIZE*0.75 gives you a float, I would rather use * 3 then / 4, but then it might not be accurate as this returns an integer. Basicly for x,y positions on screen you should be able to calculate an integer that matches wanted position, as everything on screen are x and y coords. Disclaimer: I never did this, just my theory.