I am trying to write a program to display a hexagon. The only values I know are a starting point, e.g. {0, 0}
How can I know the other 5 points if I want each length to be 2 units long for example.
The interior angle of a hexagon is 120%.
But I am struggling to know how to get the next points from the starting position and knowing the above facts.
I have found this code:
export const createPoints = (startingPoint: Point) => {
const _s32 = Math.sqrt(3) / 2;
const A = 25;
const xDiff = 100;
const yDiff = 100;
return [
[A + xDiff, 0 + yDiff],
[A / 2 + xDiff, A * _s32 + yDiff],
[-A / 2 + xDiff, A * _s32 + yDiff],
[-A + xDiff, 0 + yDiff],
[-A / 2 + xDiff, -A * _s32 + yDiff],
[A / 2 + xDiff, -A * _s32 + yDiff]
];
};
But I do not understand the calculation.
_s32 is the square root of 3 divided by two
The trick is to rotate the hexagon around the center of its mass, then you just need to rotate the radius by 60 degrees to get each point. Here's a pseudo code
Note I have written all angles in degrees - you will want to convert them to radians multiplying them by $\pi / 180$