Animating the movement of a figure

28 views (last 30 days)
Iñigo de la Joya
Iñigo de la Joya on 12 Dec 2019
Edited: Andreas Bernatzky on 18 Dec 2019
I have written a code which makes makes a rectangle rotate about a certain point bya certain angle anticlockwise, but when I proceed on the animation, it draws every single rectangle as it is rotated. How can I make the rectangle rotate without leaving a trace after every iteration?
Here is the code which inolves some funtions:
function [colouredshape] = filledshape(shape,c)
% This function will draw a shape that is filled of a certain colour
function [finalshape] = rotateabout(shape,a,x,y)
% this function will rotate a shape anticlockwise about a certain point rather than the
% origin (angle a, coordinates (x,y))
[newshape] = translate(-x,-y,shape);
[rotatedshape] = rotate(newshape,a);
[finalshape] = translate(x,y,rotatedshape);
% This is animation
n = 10;
rectangle1 = [10 10 11 11 10; 1 5 5 1 1];
for a = linspace(0,pi/2,n)
[finalshape] = rotateabout(rectangle1,a,10,5);

Answers (1)

Andreas Bernatzky
Andreas Bernatzky on 13 Dec 2019
Edited: Andreas Bernatzky on 13 Dec 2019
A rough and quick example:
RectangleData = calcRectangle(n); %calculate your new position
hRectangle = plot(RectangleData); % plot your rectangle
% Now get rid of it.
delete(hRectangle); %clear your plot
I can not test your code at the moment. But try the delete() after your pause()
Hope I could help
Andreas Bernatzky
Andreas Bernatzky on 18 Dec 2019
The strange pattern is normal because I use the rand() function.chaos.PNG
you should see some blue and white shapes. (look at picture)
Maybe my example was a little bit confusing.
For your question:
FigureStorage = plot(someXvalues,someYvalues);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by