围绕中心圆分布圆 [英] Distribute circles around a center circle

查看:136
本文介绍了围绕中心圆分布圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在中心圆周围放置六个圆. 它们中的每一个都具有相同的直径,因此应该有可能将它们围绕中心放置而在它们之间没有空间或重叠. 我认为应该接近解决方案,但有一点重叠. 我找不到如何进行完美计算的答案.

I'm trying to place six circles around a center circle. Eeach of them has the same diameter so it should be possible to place them around the center without space between or overlaps. I thinking to be close to the solution but there are small overlaps. I can't find an answer how to get a perfect calculation.

那是我当前的结果:

以及我的计算方式:

this.distribute = function () {

    var surfaceSize = this.surface.getAbsoluteSize(),
        i,
        x = 0,
        y = 0;

    // 7 CIRCLES 6 AFFECTED
    for (i = 0; i < this.config.length; i += 1) {
        var oBall = this.getBall(i);


        if (i > 0) {
            x = oBall.config.size.width * Math.sin(i);
            y = oBall.config.size.height * Math.cos(i);
        }

        oBall.node.setPosition(x, y, 0);
    }
};

预先感谢

推荐答案

只需玩60 deg === PI/3:

http://jsfiddle.net/coma/nk0ms9hb/

var circles = document.querySelectorAll('div.circles > div');

Array.prototype.forEach.call(circles, function (circle, index) {

    var angle = index * Math.PI / 3;

    circle.style.top = Math.sin(angle) + 'em';
    circle.style.left = Math.cos(angle) + 'em';
});

我正在使用ems简化2 * radius === 1em

I'm using ems to ease the calculations like 2 * radius === 1em

这篇关于围绕中心圆分布圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆