我正试图找到一种方法,尽可能多地将六边形放在一个圆圈中.到目前为止,我获得的最好结果是从中心向外以圆形形状生成六边形.
但我认为我的计算得到最大六边形圆是错误的,尤其是我使用的部分Math.ceil()和Math.Floor函数来向下舍入/向上舍入一些值.
使用时Math.ceil(),六边形有时会与圆形重叠.另一方面,
当使用Math.floor()时,它有时会在最后一圈六边形和圆形边框之间留下太多空间.
var c_el = document.getElementById("myCanvas");
var ctx = c_el.getContext("2d");
var canvas_width = c_el.clientWidth;
var canvas_height = c_el.clientHeight;
var PI=Math.PI;
var PI2=PI*2;
var hexCircle = {
r: 110, /// radius
pos: {
x: (canvas_width / 2),
y: (canvas_height / 2)
}
};
var hexagon = {
r: 20,
pos:{
x: 0,
y: 0
},
space: 1
};
drawHexCircle( hexCircle, hexagon );
function drawHexCircle(hc, hex ) {
drawCircle(hc);
var …Run Code Online (Sandbox Code Playgroud)