Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

#ActualDrMadolite

Posted 12 August 2012 - 08:41 AM

Here's a simple algorithm on adding an "almost-perfect" hex (it just looks good, but isn't actually perfect - the diagonal lines are about 10% longer than the vertical ones):

For a vertical (pointy) hexagon w/ an outer diameter of 100 pixels (length between two opposing angles):

1. Start drawing a line from x, y-50 (x and y = center of hex) ==> x-50, y-25. (top left diagonal)
2. Draw a line from x-50, y-25 ==> x-50, y+25. (left vertical)
3. Draw a line from x-50, y+25 ==> x, y+50. (bottom left diagonal)
4. Draw a line from x, y+50 ==> x+50, y+25. (bottom right diagonal)
5. Draw a line from x+50, y+25 ==> x+50, y-25. (right vertical)
6. Draw a line from x+50, y-25 ==> x, y-50. (top right diagonal)

Notice how you can apply this to any size (+/- 25 is 25% of outer diameter, while +/-50 is 50%, so for a 40-pixel hexagon this would be +/- 10px and +/- 20px, respectively). Note however, that the smaller a hexagon is, the more difference there'll be between vertical/horizontal sides and diagonal sides, because a vertical/horizontal line cannot be a decimal number of pixels in length (although diagonal lines can, as long as both its x and y span equals an integer number of pixels).

====================

Thankfully, in programming, there's really no reason to make the hexes absolutely perfect. As long as they look good, opposing sides are of same length (e.g. top right == lower left) and the hexes are drawn at minimum processing, they work.

#17DrMadolite

Posted 12 August 2012 - 08:40 AM

Here's a simple algorithm on adding an "almost-perfect" hex (it just looks good, but isn't actually perfect - the diagonal lines are about 10% longer than the vertical ones):

For a vertical (pointy) hexagon w/ an outer diameter of 100 pixels (length between two opposing angles):

1. Start drawing a line from x, y-50 (x and y = center of hex) ==> x-50, y-25. (top left diagonal)
2. Draw a line from x-50, y-25 ==> x-50, y+25. (left vertical)
3. Draw a line from x-50, y+25 ==> x, y+50. (bottom left diagonal)
4. Draw a line from x, y+50 ==> x+50, y+25. (bottom right diagonal)
5. Draw a line from x+50, y+25 ==> x+50, y-25. (right vertical)
6. Draw a line from x+50, y-25 ==> x, y-50. (top right diagonal)

Notice how you can apply this to any size (+/- 25 is 25% of outer diameter, while +/-50 is 50%, so for a 40-pixel hexagon this would be +/- 10px and +/- 20px, respectively). Note however, that the smaller a hexagon is, the more difference there'll be between vertical/horizontal sides and diagonal sides, because a vertical/horizontal line cannot be a decimal number of pixels in length (although diagonal lines can, as long as both its x and y span equals an integer number of pixels).

====================

Thankfully, in programming, there's really no reason to make the hexes absolutely perfect. As long as they look good, the opposing sides are the same length and the hexes are drawn at minimum processing, they work.

#16DrMadolite

Posted 12 August 2012 - 08:40 AM

Here's a simple algorithm on adding an "almost-perfect" hex (it just looks good, but isn't actually perfect - the diagonal lines are about 10% longer than the vertical ones):

For a vertical (pointy) hexagon w/ an outer diameter of 100 pixels (length between two opposing angles):

1. Start drawing a line from x, y-50 (x and y = center of hex) ==> x-50, y-25. (top left diagonal)
2. Draw a line from x-50, y-25 ==> x-50, y+25. (left vertical)
3. Draw a line from x-50, y+25 ==> x, y+50. (bottom left diagonal)
4. Draw a line from x, y+50 ==> x+50, y+25. (bottom right diagonal)
5. Draw a line from x+50, y+25 ==> x+50, y-25. (right vertical)
6. Draw a line from x+50, y-25 ==> x, y-50. (top right diagonal)

Notice how you can apply this to any size (+/- 25 is 25% of outer diameter, while +/-50 is 50%, so for a 40-pixel hexagon this would be +/- 10px and +/- 20px, respectively). Note however, that the smaller a hexagon is, the more difference there'll be between vertical/horizontal sides and diagonal sides, because a vertical/horizontal line cannot be a decimal number of pixels in length (although diagonal lines can, as long as both its x and y span equals an integer number of pixels).

====================

Thankfully, in programming, there's usually no reason to make the hexes absolutely perfect. As long as they look good, the opposing sides are the same length and the hexes are drawn at minimum processing, they work.

#15DrMadolite

Posted 12 August 2012 - 08:39 AM

Here's a simple algorithm on adding an "almost-perfect" hex (it just looks good, but isn't actually perfect - the diagonal lines are about 10% longer than the vertical ones):

For a vertical (pointy) hexagon w/ an outer diameter of 100 pixels (length between two opposing angles):

1. Start drawing a line from x, y-50 (x and y = center of hex) ==> x-50, y-25. (top left diagonal)
2. Draw a line from x-50, y-25 ==> x-50, y+25. (left vertical)
3. Draw a line from x-50, y+25 ==> x, y+50. (bottom left diagonal)
4. Draw a line from x, y+50 ==> x+50, y+25. (bottom right diagonal)
5. Draw a line from x+50, y+25 ==> x+50, y-25. (right vertical)
6. Draw a line from x+50, y-25 ==> x, y-50. (top right diagonal)

Notice how you can apply this to any size (+/- 25 is 25% of outer diameter, while +/-50 is 50%, so for a 40-pixel hexagon this would be +/- 10px and +/- 20px, respectively). Note however, that the smaller a hexagon is, the more difference there'll be between vertical/horizontal sides and diagonal sides, because a vertical/horizontal line cannot be a decimal number of pixels in length (although diagonal lines can, as long as both its x and y span equals an integer number of pixels).

====================

Thankfully, in programming, there's usually no reason to make the hexes absolutely perfect. As long as they look good and are drawn fast, they work.

#14DrMadolite

Posted 12 August 2012 - 08:38 AM

Here's a simple algorithm on adding an "almost-perfect" hex (it just looks good, but isn't actually perfect - the diagonal lines are about 10% longer than the vertical ones):

For a vertical (pointy) hexagon w/ an outer diameter of 100 pixels (length between two opposing angles):

1. Start drawing a line from x, y-50 (x and y = center of hex) ==> x-50, y-25. (top left diagonal)
2. Draw a line from x-50, y-25 ==> x-50, y+25. (left vertical)
3. Draw a line from x-50, y+25 ==> x, y+50. (bottom left diagonal)
4. Draw a line from x, y+50 ==> x+50, y+25. (bottom right diagonal)
5. Draw a line from x+50, y+25 ==> x+50, y-25. (right vertical)
6. Draw a line from x+50, y-25 ==> x, y-50. (top right diagonal)

Notice how you can apply this to any size (+/- 25 is 25% of outer diameter, while +/-50 is 50%, so for a 40-pixel hexagon this would be +/- 10px and +/- 20px, respectively). Note however, that the smaller a hexagon is, the more difference there'll be between vertical/horizontal sides and diagonal sides, because a vertical/horizontal line cannot be a decimal number of pixels in length (although diagonal lines can, as long as both its x and y span amounts to an integer number of pixels).

====================

Thankfully, in programming, there's usually no reason to make the hexes absolutely perfect. As long as they look good and are drawn fast, they work.

#13DrMadolite

Posted 12 August 2012 - 05:49 AM

Here's a simple algorithm on adding an "almost-perfect" hex (it just looks good, but isn't actually perfect - the diagonal lines are about 10% longer than the vertical ones):

For a vertical (pointy) hexagon w/ an outer diameter of 100 pixels (length between two opposing angles):

1. Start drawing a line from x, y-50 (x and y = center of hex) ==> x-50, y-25. (top left diagonal)
2. Draw a line from x-50, y-25 ==> x-50, y+25. (left vertical)
3. Draw a line from x-50, y+25 ==> x, y+50. (bottom left diagonal)
4. Draw a line from x, y+50 ==> x+50, y+25. (bottom right diagonal)
5. Draw a line from x+50, y+25 ==> x+50, y-25. (right vertical)
6. Draw a line from x+50, y-25 ==> x, y-50. (top right diagonal)

Notice how you can apply this to any size (+/- 25 is 25% of outer diameter, while +/-50 is 50%, so for a 40-pixel hexagon this would be +/- 10px and +/- 20px, respectively). Note however, that the smaller a hexagon is, the more difference there'll be between vertical/horizontal sides and diagonal sides, because a vertical/horizontal line cannot be a decimal number of pixels in length (although diagonal lines can, as long as both its x and y span amounts to a non-decimal number of pixels).

====================

Thankfully, in programming, there's usually no reason to make the hexes absolutely perfect. As long as they look good and are drawn fast, they work.

PARTNERS