旋轉這是原帖的延續:陣列沿橢圓自己的中心點
Calculate ellipse size in relation to distance from center point
我試圖創建橢圓,一直以來自己的旋轉中心旋轉的網格。然後,我試圖通過中心點縮放橢圓的「正方形網格」,同時仍然允許它們沿着它們各自的中心點旋轉。
ArrayList<RotatingEllipse> ellipses = new ArrayList<RotatingEllipse>();
void setup() {
size(500, 500);
noStroke();
smooth();
ellipses.add(new RotatingEllipse(width*.25, height*.25));
ellipses.add(new RotatingEllipse(width*.75, height*.75));
ellipses.add(new RotatingEllipse(width*.75, height*.25));
ellipses.add(new RotatingEllipse(width*.25, height*.75));
ellipses.add(new RotatingEllipse(width/2*.25, height/2*.25));
ellipses.add(new RotatingEllipse(width/2*.75, height/2*.75));
ellipses.add(new RotatingEllipse(width/2*.75, height/2*.25));
ellipses.add(new RotatingEllipse(width/2*.25, height/2*.75));
}
void draw() {
background(#202020);
for (RotatingEllipse e : ellipses) {
e.stepAndDraw();
}
}
class RotatingEllipse {
float rotateAroundX;
float rotateAroundY;
float distanceFromRotatingPoint;
float angle;
public RotatingEllipse(float startX, float startY) {
rotateAroundX = (width/2 + startX)/2;
rotateAroundY = (height/2 + startY)/2;
distanceFromRotatingPoint = dist(startX, startY, rotateAroundX, rotateAroundY);
angle = atan2(startY-height/2, startX-width/2);
}
public void stepAndDraw() {
angle += PI/128;
float x = rotateAroundX + cos(angle)*distanceFromRotatingPoint;
float y = rotateAroundY + sin(angle)*distanceFromRotatingPoint;
float distance = dist(x, y, width/2, height/2);
// size of ellipses
float diameter = 50*(200-distance)/500;
ellipse(x, y, diameter, diameter);
}
}
你的問題到底是什麼?這個更新後的代碼不符合你的期望? –
我添加了錯誤的代碼,我附加了剛剛添加橢圓的正確部分。我認爲增加寬度/ 2和高度/ 2將允許將橢圓放置在兩個外部橢圓之間,但結果是完全不同的。這個問題或多或少與圖表有關,它詢問我如何在兩個外部橢圓之間添加橢圓,以及如何通過中心點縮放所有這些旋轉橢圓。謝謝 –