3
我正在尝试使某些对象(如12)在处理中不断旋转到椭圆路径中。我得到了一个可以在一个圆圈内旋转的草图,并且我想让它以椭圆形旋转。我有一些来自处理论坛的指针,但指针中的代码与我发布的代码不同,但我现在还不能理解(三角函数较弱)。在椭圆路径中旋转某些元素
我用Google搜索了一下,发现一个帖子试图用这种算法来实现这一目标:
你需要用一些参数定义椭圆:
x, y: center of the ellipse a, b: semimajor and semiminor axes
如果你想继续前进elipses这意味着你改变主轴和你在椭圆上的位置之间的角度。让 称这个角度α。
您的位置(X,Y)是:
X = x + (a * Math.cos(alpha)); Y = y + (b * Math.sin(alpha));
为了向左或向右移动,你需要增加/减少α和 然后重新计算你的位置。来源: http://answers.unity3d.com/questions/27620/move-object-allong-an-ellipsoid-path.html
如何将它集成到我的草图?谢谢。
这里是我的草图:
void setup()
{
size(1024, 768);
textFont(createFont("Arial", 30));
}
void draw()
{
background(0);
stroke(255);
int cx = 500;
int cy = 350;
int r = 300; //radius of the circle
float t = millis()/4000.0f; //increase to slow down the movement
ellipse(cx, cy, 5, 5);
for (int i = 1 ; i <= 12; i++) {
t = t + 100;
int x = (int)(cx + r * cos(t));
int y = (int)(cy + r * sin(t));
line(cx, cy, x, y);
textSize(30);
text(i, x, y);
if (i == 10) {
textSize(15);
text("x: " + x + " y: " + y, x - 50, y - 20);
}
}
}
谢谢,安德鲁!有用。 :) – Scott 2012-02-06 06:18:36