We are about to switch to a new forum software. Until then we have removed the registration on this forum.
How much do I rotate a regular polygon so a side is on the bottom? In my example below, the polygons are always on an angle when they are first drawn.
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
// Setup canvas
background(243, 242, 243);
translate(width * 0.5, height * 0.5);
// Setup polygon colours
strokeWeight(4);
stroke(0);
fill(243, 242, 243);
// Create polygon
createPolygon(0, 0, 200, 16);
}
function createPolygon(x, y, radius, sides) {
let angle = TWO_PI / sides;
beginShape();
for (let i = 0; i < TWO_PI; i += angle) {
var ax = x + cos(i) * radius;
var ay = y + sin(i) * radius;
vertex(ax, ay);
}
endShape(CLOSE);
}
I have worked out that for polygons with a number of sides that is a binary number, you can rotate it by PI / sides
radians, and it will be flat. It doesn't work for any other polygons with a non-binary number of sides. What equation do I use to find how much I should rotate it?
Answers
I've also just worked out that if you rotate a polygon with an odd number of sides by
PI * 1.5
, it works how I want.By a binary number of sides, do you mean an even number, like 2 4 6...?
Another way of putting this is: I want to rotate a shape by "(one half) (a side)" : (1/2)*(2PI/sides).