4

Processingで楕円パスで連続的に回転するように、12などのオブジェクトを作成しようとしています。円で回転するスケッチを手に入れたので、楕円で回転させたいです。処理フォーラムからいくつかのポインターがありますが、ポインターのコードは私が投稿したコードとは異なり、まだ理解できませんでした (三角法に弱い)。

私は少しグーグルで、このアルゴリズムでこれを達成しようとしている投稿を見つけました:

いくつかのパラメーターを使用して楕円を定義する必要があります。

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

楕円上を移動したい場合、これは長軸と楕円上の位置の間の角度を変更することを意味します。この角度をアルファとしましょう。

あなたの位置 (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);
        }
    }
}
4

1 に答える 1

3

交換

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));
于 2012-02-06T05:20:27.393 に答える