gpt4 book ai didi

processing - 在椭圆路径中旋转一些元素

转载 作者:行者123 更新时间:2023-12-02 00:25:02 27 4
gpt4 key购买 nike

我正在尝试制作一些对象,比如 12,在 Processing 中以椭圆路径连续旋转。我有一个以圆形旋转的草图,我想让它以椭圆形旋转。我有一些来自处理论坛的指针,但指针中的代码与我发布的代码不同,我还无法理解(三角学弱)。

我用谷歌搜索了一下,发现了一篇试图用这个算法实现这一目标的帖子:

You need to define your ellipse with a few parameters:

x, y: center of the ellipse
a, b: semimajor and semiminor axes

If you want to move on the elipses this means that you change the angle between the major axes and your position on the ellipse. Lets call this angle alpha.

Your position (X,Y) is:

X = x + (a * Math.cos(alpha));
Y = y + (b * Math.sin(alpha));

In order to move left or right you need to increase/decrease alpha and then recalculate your position. Source: 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);
}
}
}

最佳答案

代替

int r = 300; //radius of the circle


int a = 350; // major axis of ellipse
int b = 250; // minor axis of ellipse

并替换
int x = (int)(cx + r * cos(t));
int y = (int)(cy + r * sin(t));


int x = (int)(cx + a * cos(t));
int y = (int)(cy + b * sin(t));

关于processing - 在椭圆路径中旋转一些元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9155750/

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