以下是以螺旋方式排列圆圈的算法。
遵循顺时针方向。
![enter image description here](https://i.stack.imgur.com/BqenV.png)
以下是伪代码(总体)。
let dir = [1, 0]
function checkIntersect(c0, c1) {
const {x0, y0, r0} = c0
const {x1, y1, r1} = c1
return Math.hypot(x0-x1, y0-y1) <= (r0 + r1);
}
for (let i = 0; i < circleCount; i++) {
for (let j = 0; j < circleCount; j++) {
if (checkIntersect(circles[i], circles[j])) {
incrementLocation(circles[j])
flip(dir)
}
}
}
这就是我想出的螺旋式,但它不起作用!
const spiralRadii = 3;
for (let i = 1; i <= radius; i++) {
let x = 0;
let y = 0;
for (let j = 0; j <= 2 * i; j++) {
if (i % 2 === 0) {
if (j <= i) {
x--;
console.log(x, y);
} else {
y++;
console.log(x, y);
}
} else {
if (j <= i) {
x++;
console.log(x, y);
} else {
y--;
console.log(x, y);
}
}
}
}
以这种方式,我怎样才能以顺时针螺旋方式用带有地址的圆圈填充整个空间?
![enter image description here](https://i.stack.imgur.com/FHXrX.png)
在每次迭代期间始终遵循顺时针方向 && 检查顺时针方向是否被占用,如果没有将其他所有内容移动到该位置(同时将当前的保持在前一个位置),
如果被占用则向前移动
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)