PDA

查看完整版本 : 动画多个椭圆


poster
2019-12-10, 20:41
sRMatTemp = [SENSORRANGE]; sRMat = repmat(sRMatTemp, size(obj.landmarks.sensed(:,1), 1)); ellipse(((2*pi*sRMat)/(360/obj.landmarks.sensed(:,4))), obj.landmarks.sensed(:,5) , obj.landmarks.sensed(:,3), obj.landmarks.apparentPositionsST(:,1), obj.landmarks.apparentPositionsST(:,2)); 上面的代码工作正常...一次。问题是我需要设置动画。每次绘制椭圆时,它们都会留在我的屏幕上,并且该图立即变得不可读。

上面的代码也可以很好地用于动画散点图。有什么办法可以将它与椭圆结合使用吗?

我正在使用Mathworks社区站点上的ellipse.m。

fig=figure; axes('NextPlot','add'); set(fig, 'name', 'Animated Graph') l.st=scatter([0],[0],'g.'); set(l.st,'XData',obj.landmarks.apparentPositionsST(:,1),'YData',obj.landmarks.apparentPositionsST(:,2)); drawnow

回答:

您需要将EraseMode属性设置为xor以便在更新其X / Y数据时,它将删除其旧位置,然后重绘。确保您阅读了此动画指南 (http://web.archive.org/web/20100516134610/http://www.mathworks.com/support/tech-notes/1200/1204.html#Section%2023) 。

我写了一个简单的例子来说明动画椭圆。我正在使用上一个问题中关于SO的功能calculateEllipse.m (https://stackoverflow.com/questions/2153768/matlab-to-draw-ellipse-and-ellipsoid/2155456#2155456) 。

step = linspace(50,200,100); figure hAx = axes('XLim',[-250 250], 'YLim',[-250 250], ... 'Drawmode','fast', 'NextPlot','add'); axis(hAx, 'equal') p = calculateEllipse(0, 0, step(1), step(end), step(1)); hLine = line('XData',p(:,1), 'YData',p(:,2), 'EraseMode','xor', ... 'Color','r', 'LineWidth',3); for i=1:numel(step) p = calculateEllipse(0, 0, step(i), step(numel(step)-i+1), step(i)); set(hLine,'XData',p(:,1), 'YData',p(:,2)) %# update X/Y data pause(.05) %# slow down animation drawnow %# force refresh if ~ishandle(hLine), return; end %# in case you close the figure end https://i.stack.imgur.com/wDzdP.gif (https://i.stack.imgur.com/wDzdP.gif)



更多&回答... (https://stackoverflow.com/questions/3188142)