주요 콘텐츠

원 내부의 삼각형 애니메이션하기

이 예제에서는 삼각형의 데이터 속성을 업데이트하여 원 내부를 도는 삼각형 애니메이션을 작성하는 방법을 보여줍니다.

원을 플로팅하고, 데이터 단위(Data Unit)가 두 방향 모두에서 동일하도록 축 제한을 설정합니다.

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) 좌표를 사용하여 삼각형 꼭짓점 중 하나에 대한 값을 변경합니다. 루프의 값을 변경하여 애니메이션을 생성합니다. 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

참고 항목

함수

도움말 항목