How can I add a point to an animation?

조회 수: 11 (최근 30일)
BeHu
BeHu 2018년 6월 26일
답변: Sammit Jain 2018년 6월 27일
I want to add the point b3 to the animation so that every in the end every b3 is in the animation
r =0;
s= 2;
z = [15, 0; 7, 10; 3, 4; 3, 6];
axis(gca, 'equal');
axis([0 16 0 20]);
k = 1;
for t = r:0.01:s
...
b3 = (1 - lambda ) * b2(1,:) + lambda * b2(2, :);
i
crank1 = line(z(:,1), z(:,2));
crank2 = line(b1(:,1), b1(:,2));
crank3 = line(b2(:,1), b2(:,2));
crank4 = line(b3(1), b3(2));
pause(0.1);
delete(crank1);
delete(crank2);
delete(crank3);
delete(crank4);
end
x = b3;
end
  댓글 수: 1
KSSV
KSSV 2018년 6월 27일
Most of the variables are not defined..what is b3? it's dimensions?

댓글을 달려면 로그인하십시오.

답변 (2개)

Sayyed Ahmad
Sayyed Ahmad 2018년 6월 27일
you need to add in your code
hold on
otherweise you create every time a new graph and your point is not exist anymore.

Sammit Jain
Sammit Jain 2018년 6월 27일
Hi, since the exact context of the code isn't clear, I'm making the following assumptions:
  • You're probably trying to simulate/animate some form of a crank-slider mechanism.
  • You're opening a figure window and plotting these lines continuously. These coordinates are updated in a for loop
  • b3 is one point represented as [x,y]. (From the code it looks like it's a weighted average based on lambda)
In this case, your question boils down to representing a single point in a plot window. Now since you're animating, a simple way for you to do this is to use the 'viscircles' command. This will allow you to make an approximate representation of a point with a tiny circle.
Check out the documentation for viscircles
With this you can make a visual representation of the ‘point’ by centering a circle on the x,y coordinates for the point (which are stored in b3), with a small radius. The circle will be drawn using the afore-mentioned viscircles command. You will have to choose a radius according to the scale of your animation.
Hope this helps.

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by