Reputation: 1476
I haven't done any geometry in such a long time that I cannot figure out how to do this.
I created this method:
public Polygon getHex(int posX, int posY) {
Polygon hex = new Polygon();
for (int i = 0; i < 6; i++) {
hex.addPoint((int) (posX + (50 * Math.cos(i * 2 * Math.PI / 6))),
(int) (posY + (50 * Math.sin(i * 2 * Math.PI / 6))));
}
return hex;
}
This creates a equilateral Hexagon like this:
_
/ \
\_/
I need a rotated, equilateral hexagon like this:
/\
| |
\/
Can anybody help me remember math? Thank you
Upvotes: 1
Views: 1231
Reputation: 18424
Change i * 2
to (1 + i * 2)
, that will rotate all of your points by pi/6, which should do the trick!
Upvotes: 4