OK, I mentioned my hexagon game.
But I've been trying to figure out a basic algorithm for rendering hexagons. ie: dimensions.
I thought I found it once online, but when I looked, it wasn't quite what I thought it was.
basically, what I need to do is plot the six points.
the first two points are easy. They're the endpoints of line 1 - the top line of the hex.
L1 = Top line
L2 = Diagonal starting at rightmost end of top-line and ending at the rightmost point of the hexagon halfway between top and bottom line.
L3 = Diagonal at end of L2, going back to same X-Position of L1, but lower Y position.
L4 = Bottom Line - it's endpoint is at the end point of L3, and it's beginning is same X as L1, but again, lower on the Y-axis...
L5 = end point is beginning point of L4, and heads up to the leftmost point of hexagon.
L6 = closing line, beginning is leftpoint of hexagon, and ends at the beginning X,Y co-ordinates.
So, let's give all the sides a length of say... 64.
(offset is needed for the space between leftmost point of hex and the beginning of line one, this offset is the number of pixels difference between the X point of the leftmost point, and the X point of Line1)
Then:
Length = 64;
L1p1.x = 0 + offset;
L1p1.y = 0;
L1p2.x = L1.X1 + Length;
L1p2.y = 0;
-------
NOW! where the fuck do I go? What sort of ratio do I use to plot the next point that is the end of L2?
so, example:
L2p1.x = L1p2.x;
L2p1.y = L1p2.y;
L2p2.x = ???????????????????
L2p2.y = ???????????????????
-------
See, Line 2, point 1(the beginning point of Line 2) is the same as the end point of Line 1(Line 1, Point 2, X; Line 1, Point 2, Y)
but now how do I calc Line 2, point 2, x?
The trick is to do this so it's a regular hexagon, and not just willy nilly shit.
Any tips or ideas on either how to do this or what method I might use to figure it out?
I tried to use the Pythagorean theorem, but the problem is that I only have the "c" part, the length of the line, and so I can't use the theorem, because I don't have a second part, cuz those are what I need.
sigh.
You're probably no longer reading this. whatever.
bye.
But I've been trying to figure out a basic algorithm for rendering hexagons. ie: dimensions.
I thought I found it once online, but when I looked, it wasn't quite what I thought it was.
basically, what I need to do is plot the six points.
the first two points are easy. They're the endpoints of line 1 - the top line of the hex.
L1 = Top line
L2 = Diagonal starting at rightmost end of top-line and ending at the rightmost point of the hexagon halfway between top and bottom line.
L3 = Diagonal at end of L2, going back to same X-Position of L1, but lower Y position.
L4 = Bottom Line - it's endpoint is at the end point of L3, and it's beginning is same X as L1, but again, lower on the Y-axis...
L5 = end point is beginning point of L4, and heads up to the leftmost point of hexagon.
L6 = closing line, beginning is leftpoint of hexagon, and ends at the beginning X,Y co-ordinates.
So, let's give all the sides a length of say... 64.
(offset is needed for the space between leftmost point of hex and the beginning of line one, this offset is the number of pixels difference between the X point of the leftmost point, and the X point of Line1)
Then:
Length = 64;
L1p1.x = 0 + offset;
L1p1.y = 0;
L1p2.x = L1.X1 + Length;
L1p2.y = 0;
-------
NOW! where the fuck do I go? What sort of ratio do I use to plot the next point that is the end of L2?
so, example:
L2p1.x = L1p2.x;
L2p1.y = L1p2.y;
L2p2.x = ???????????????????
L2p2.y = ???????????????????
-------
See, Line 2, point 1(the beginning point of Line 2) is the same as the end point of Line 1(Line 1, Point 2, X; Line 1, Point 2, Y)
but now how do I calc Line 2, point 2, x?
The trick is to do this so it's a regular hexagon, and not just willy nilly shit.
Any tips or ideas on either how to do this or what method I might use to figure it out?
I tried to use the Pythagorean theorem, but the problem is that I only have the "c" part, the length of the line, and so I can't use the theorem, because I don't have a second part, cuz those are what I need.
sigh.
You're probably no longer reading this. whatever.
bye.
no subject
Date: 2003-08-17 12:41 am (UTC)2:(L,0)
3:(L(1+√3/2),-L/2)
4:(L,-L)
5:(0,-L)
6:(-L√3/2,-L/2)
where L is the length of a side. this starts at the top left, and goes clockwise down. hence all the negative signs.
no subject
Date: 2003-08-17 12:53 am (UTC)may I ask how you got this info? did you calc it out or find it in a book or online? whatever it is, it's greatly appreciated. :)
If this damn thing ever gets made, you'll get credited...
no subject
Date: 2003-08-17 01:00 am (UTC)answering math questions is one of my favorite things, so this was an enjoyable find on my friends list. thanks.
no subject
Date: 2003-08-17 01:37 pm (UTC)they're still just a tad off, but perhaps that's because I have to cast the floating numbers into an integer, so they're rounding off awkwardly? Maybe I should talk to a programmer about this part(or do you program and have a clue what I mean?)
anyways, I'll work on translation into screen co-ordinates and see if I can get it to work.
no subject
Date: 2003-08-17 02:12 pm (UTC)i am not a programmer, but i certainly know how to code. i m pretty sure i know what you re trying to do, but i am not sure what the layout of your drawing environment is, but if it numbers from the top left and increases down, then you just need to change the negatives to positives.
note that if you start at the top left, then your 6th point will be off the screen to the left.
if the hexagon still doesn t look regular, it could be due to rounding errors, but it might also be because the pixels are not square.
no subject
Date: 2003-08-17 02:24 pm (UTC)The info you gave me started me on the right path, so, again I appreciate it...
Also, I am not a programmer. heh. I suppose that's scary to program a game, when you're not a programmer, eh?
no subject
Date: 2003-08-17 02:46 pm (UTC)can i change my answer?
(0,0)
(1,0)
(3/2,-√3/2)
(1,-√3)
(0,-√3)
(-1/2,-√3/2)
once again, change the negatives to positives, and shift the whole thing to the right, to make all your numbers positive, or whatever you need to do.
lemme know if that works a little better.
no subject
Date: 2003-08-17 02:38 pm (UTC)