[personal profile] symbioidlj
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.

Date: 2003-08-17 12:41 am (UTC)
From: [identity profile] ziggurat.livejournal.com
1:(0,0)
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.

Date: 2003-08-17 12:53 am (UTC)
From: [identity profile] symbioid.livejournal.com
damn! thanks much...

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

Date: 2003-08-17 01:00 am (UTC)
From: [identity profile] ziggurat.livejournal.com
a regular hexagon has 120 degrees for all its internal angles. so to plot all the points, you just turn 120 degrees at each vertex. use sine and cosine of 120 to get the horizontal and vertical shifts.

answering math questions is one of my favorite things, so this was an enjoyable find on my friends list. thanks.

Date: 2003-08-17 01:37 pm (UTC)
From: [identity profile] symbioid.livejournal.com
hmmmmm... are you using cartesian co-ordinates? I think you maybe, because it's not quite right... I'm trying to translate into standard screen geometry( (0,0) is upper left)... cartesian would be the lower left...

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.

Date: 2003-08-17 02:12 pm (UTC)
From: [identity profile] ziggurat.livejournal.com
yes, i m using cartesian coordinates.

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.

Date: 2003-08-17 02:24 pm (UTC)
From: [identity profile] symbioid.livejournal.com
Yeah, I'm fucking with it now, and came up with an approximation. I had to basically increase the decimal notation before converting the floats to an integer... I did some inversions of the signs(as you suggest) and tweaked it. The code is ugly. I have to clean it up. I'm gonna post it soon, along with screen shot.

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?

Date: 2003-08-17 02:46 pm (UTC)
From: [identity profile] ziggurat.livejournal.com
oh shit! i did get my sines and cosines backwards! oops!

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.

Date: 2003-08-17 02:38 pm (UTC)
From: [identity profile] renwick.livejournal.com
I wish I was smart enough to understand what any of that stuff means. I suck ass at math.

Profile

symbioidlj: (Default)
symbioidlj

November 2015

S M T W T F S
1 234567
891011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Mar. 16th, 2026 08:54 pm
Powered by Dreamwidth Studios