メインコンテンツ

円に内接する三角形のアニメーション化

この例では、三角形のデータ プロパティを更新することで、円に内接しながら回転する三角形をアニメーション化する方法を説明します。

円をプロットし、X 軸方向と Y 軸方向でデータ単位が等しくなるように軸の範囲を設定します。

theta = linspace(-pi,pi);
xc = cos(theta);
yc = -sin(theta);
plot(xc,yc)
axis equal

Figure contains an axes object. The axes object contains an object of type line.

fill 関数を使用して平面の三角形を描画します。次に、円の ("x", "y") 座標を使用して、三角形の頂点の 1 つの値を変更します。ループ内の値を変化させて、アニメーションを作成します。ループを反復するたびに更新結果を表示するには、drawnowまたは drawnow limitrate コマンドを使用します。drawnow limitrate は最速ですが、画面に一部のフレームを描画しないことがあります。

xt = [-1 0 1 -1];
yt = [0 0 0 0];
hold on
t = fill(xt,yt,"b"); % initial flat triangle
hold off
for j = 1:length(theta)-10
    xt(2) = xc(j); % determine new vertex value
    yt(2) = yc(j); 
    t.XData = xt; % update data properties 
    t.YData = yt;
    drawnow % display updates
end

Figure contains an axes object. The axes object contains 2 objects of type line, patch.

アニメーションでは、三角形が円に内接しながら回転する様子が表示されます。

Animation of a triangle looping around the inside of a circle

参考

関数

トピック