gpt4 book ai didi

actionscript-3 - 什么是围绕一个点定位 8 个圆圈的优雅方式

转载 作者:行者123 更新时间:2023-12-04 06:43:30 25 4
gpt4 key购买 nike

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);
}

将球定位在某个点周围的最佳方法是什么,比如彼此相距 5-10 的距离,有什么公式吗?

最佳答案

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);
}

关于actionscript-3 - 什么是围绕一个点定位 8 个圆圈的优雅方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13780252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com