continuously re-plot using plot3 with same axis

12 次查看(过去 30 天)
I'm using the code given here to plot a box. My goal is to plot a box, keep it on the screen for ~.1 second, and then re-plot a different box and repeat this whole process a bunch of times (using a for loop and the hold on / hold off features).
However, when I use plot3, for every new plot, a new axis and scaling is formed. Is there a way to keep the same axis and scaling for all plots, and only re-plot the points/graph, NOT the entire figure?

回答(2 个)

John BG
John BG 2016-3-16
In C Moler experiments
chap5 there is a basic example how to animate objects depicted like the box you mention
function wiggler(X)
% WIGGLE Dynamic matrix multiplication.
% wiggle(X) wiggles the 2-by-n matrix X.
% Eg: wiggle(house)
clf
shg
thetamax = uicontrol('style','slider','max',1.0, ...
'units','normalized','position',[.25 .01 .25 .04]);
delta = uicontrol('style','slider','max',.05, ...
'units','normalized','position',[.60 .01 .25 .04]);
t = 0;
stop = uicontrol('string','stop','style','toggle');
while ~get(stop,'value')
theta = (4*abs(t-round(t))-1) * get(thetamax,'value');
G = [cos(theta) sin(theta); -sin(theta) cos(theta)];
dot_to_dot(G*X);
drawnow
t = t + get(delta,'value');
end
set(stop,'string','close','value',0,'callback','close(gcf)')
the update you did not mention is the command drawnow
the shape
X = [0;1;1;0;0];
Y = [0;0;1;1;0];
Z = [0;0;0;0;0];
the input to a 3D wiggler would be
X=[X';Y';Z']
to run this 2D wiggler
X(3,:)=[]
wiggler(X)
The 3D version of the G matrix in this 2D wiggler is rotation matrix
product of Yaw Pitch and Roll
Rotation
% test2_hgtransf_rotate
ax = axes('XLim',[-1.5 1.5],'YLim',[-1.5 1.5], 'ZLim',[-1.5 1.5])
view(3); grid on; % axis equal % 'equal' left axis static in R2012, however in R2014 same option makes axis move
axis manual; % axis steady, instead of axis equal
[x y z] = cylinder([.3 0]) % generating all surfaces to assemble
h(1) = surface(x,y,z,'FaceColor','red')
h(2) = surface(x,y,-z,'FaceColor','green')
h(3) = surface(z,x,y,'FaceColor','blue')
h(4) = surface(-z,x,y,'FaceColor','cyan')
h(5) = surface(y,z,x,'FaceColor','magenta')
h(6) = surface(y,-z,x,'FaceColor','yellow')
t = hgtransform('Parent',ax) % showing parts
set(h,'Parent',t)
set(gcf,'Renderer','opengl') % assembling parts and show
drawnow
Rz=eye(4);
Sxy=Rz; % translation vector
for r = 1:.1:2*pi % CCW: COUNTER CLOCK WISE
Rz = makehgtform('zrotate',r)
Sxy = makehgtform('scale',r)
set(t,'Matrix',Rz) % apply translation and rotation with Rz*Sxy
drawnow
end
% pause(1)
%
% for r = 1:-.1:-2*pi % CW: CLOCK WISE
% Rz = makehgtform('zrotate',r)
% set(t,'Matrix',Rz)
% drawnow
% end
%
% set(t,'Matrix',eye(4)) % normalizing orientation and size to 1
Translation, this example does not keep the axis steady, but it's a translation
% test3_hgtransf_translating
ax = axes('XLim',[-2 1],'YLim',[-2 1],'ZLim',[-1 1])
view(3); grid on; axis equal
[x y z] = cylinder([.3 0]);
h(1) = surface(x,y,z,'FaceColor','red');
h(2) = surface(x,y,-z,'FaceColor','green');
h(3) = surface(z,x,y,'FaceColor','blue');
h(4) = surface(-z,x,y,'FaceColor','cyan');
h(5) = surface(y,z,x,'FaceColor','magenta');
h(6) = surface(y,-z,x,'FaceColor','yellow');
t1 = hgtransform('Parent',ax);
t2 = hgtransform('Parent',ax);
set(gcf,'Renderer','opengl')
Scaling
ax = axes('XLim',[-1.5 1.5],'YLim',[-1.5 1.5], 'ZLim',[-1.5 1.5])
view(3); grid on; axis equal
[x y z] = cylinder([.3 0]) % generating all surfaces to assemble
h(1) = surface(x,y,z,'FaceColor','red')
h(2) = surface(x,y,-z,'FaceColor','green')
h(3) = surface(z,x,y,'FaceColor','blue')
h(4) = surface(-z,x,y,'FaceColor','cyan')
h(5) = surface(y,z,x,'FaceColor','magenta')
h(6) = surface(y,-z,x,'FaceColor','yellow')
t = hgtransform('Parent',ax) % showing parts
set(h,'Parent',t)
set(gcf,'Renderer','opengl') % assembling parts and show
drawnow
Sxy=eye(4);
for r = 1:.1:6
Sxy = makehgtform('scale',r/4)
set(t,'Matrix',Sxy)
drawnow
end
pause(1)
for r = 6:-.1:1
Sxy = makehgtform('scale',r/4)
set(t,'Matrix',Sxy)
drawnow
end
set(t,'Matrix',eye(4))
set(h,'Parent',t1);h2=copyobj(h,t2)
Txy=makehgtform('translate',[-1.5 -1.5 0])
set(t2,'Matrix',Txy)
pause(2)
delete(t1)
drawnow
If you find this answer of any help solving your question, please click on the thumbs-up vote link,
thanks in advance
John

Elliot
Elliot 2016-3-17
Thanks John but I already have a method for the animations and determining all the points and everything like that. The only thing wrong currently is that a new figure window pops up, with a new axis scale, and sometimes a new orientation for every new plot. Is there a way to keep the same axis, figure window, scaling, etc. and only re-plot points on the plot?

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by