xxxxxxxxxx
56
function setup() {
createCanvas(400, 400);
noLoop();
}
function circle_divide(m, e=1e-3, t=1e-10) {
let u = -1, v = 3 / (m + 1);
let points = [];
while(u < -e) {
u = 1e-10;
for(let n = 0; n < m; n++)
u = (u + v) / (1 - u*v);
v = v - u / (m + 1);
}
for(let n = 0; n < m; n++) {
x = 2 / (1 + t*t) - 1;
y = 2*t / (1 + t*t);
t = (t + v) / (1 - t*v);
points.push({x, y});
}
return points;
}
function circle_divide2(n) {
let v = createVector(1, 0);
let points = [v.copy()];
for(let p = 1; p < n; ++p) {
points.push(v.rotate(2*PI/n).copy());
}
return points;
}
function draw() {
background(220);
noFill();
stroke(100);
let radius = 150;
circle(width/2, width/2, 2*radius);
let n = 5;
strokeWeight(6);
stroke("red");
let points = circle_divide(n);
for(let p of points) {
point( width/2 + p.x * radius,
width/2 - p.y * radius );
}
stroke("white");
strokeWeight(3);
points = circle_divide2(n);
for(let p of points) {
point( width/2 + p.x * radius,
width/2 - p.y * radius );
}
}