本文介绍了什么是优雅的方式来定位点周围8圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  VAR圈:阵列=新的Array();


对于(VAR我:= 0; I< 8;我++)
{

    VAR球:球=新球();
        ball.x = ???
        ball.y = ???
        circles.push(球);
}
 

什么是定位球周围的一些点可以说在5-10距离对方的最好办法,是有一些公式?

解决方案

 的(VAR我:= 0; I< 8;我++)
{
    VAR球:球=新球();

    //点​​有一个有用的静态功能,对于这一点,它需要两个参数
    //首先,长度,换句话说,我们希望多远从中心为
    //其次,它希望在弧度的角度,一个完整的圆就是2 * Math.PI
    //所以,我们乘与(I / 8),以将它们同样相距甚远
    VAR POS:点= Point.polar(50,(I / 8)* Math.PI * 2);

    //最后,设置球的位置
    ball.x = pos.x;
    ball.y = pos.y;

    circles.push(球);
}
 
var circles:Array = new Array();


for(var i:int = 0; i < 8; i++)
{

    var ball:Ball = new Ball();
        ball.x = ???
        ball.y = ???
        circles.push(ball);
}

What is the best way to position balls around some point lets say in 5-10 distance of each other, is there some formula?

解决方案
for(var i:int = 0; i < 8; i++)
{
    var ball:Ball = new Ball();

    // Point has a useful static function for this, it takes two parameters
    // First, length, in other words how far from the center we want to be
    // Second, it wants the angle in radians, a complete circle is 2 * Math.PI
    // So, we're multiplying that with (i / 8) to place them equally far apart
    var pos:Point = Point.polar(50, (i / 8) * Math.PI * 2);

    // Finally, set the position of the ball
    ball.x = pos.x;
    ball.y = pos.y;

    circles.push(ball);
}

这篇关于什么是优雅的方式来定位点周围8圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 13:50