我正在尝试使用matlab / octave为这个螺旋设置动画我想让它上下旋转
t = 0:0.1:10*pi;
r = linspace (0, 1, numel (t));
z = linspace (0, 1, numel (t));
plot3 (r.*sin(t), r.*cos(t), z);
我尝试使用for循环来制作动画,但这只是给我一个圆锥形状,请参阅下面的代码和图片
clear all, clc,clf,tic
t = 0:0.1:10*pi;
r = linspace (0, 1, numel (t));
z = linspace (0, 1, numel (t));
for ii=1:length(r)
ii
plot3 (r.*sin(t(ii)), r.*cos(t(ii)), z);
hold on
%pause (.00001)
end
图片
答案 0 :(得分:2)
你也可以使用comet3()
包,它通过图表激活轨迹:
delay = 0.001 % seconds
figure
comet3(r.*sin(t), r.*cos(t), z, delay);
这使得我更喜欢连续的轨迹,而不是*的离散序列。
一个缺点是,无论您使用何种延迟,Octave 3.6.4附带的comet
和comet3
版本都很慢。但是这可以通过使用以下andyras in this SO question提供的技巧来解决:
% plot the first point to get started
h = plot3(x(1),y(1),z(1),"b");
axis([min(x), max(x), min(y), max(y), min(z), max(z)]);
% refresh the plot in a loop through the rest of the data
for k = 1:length(z);
set(h, 'XData', x(1:k));
set(h, 'YData', y(1:k));
set(h, 'ZData', z(1:k));
pause (0.001); % delay in seconds
% alternatively could provide a velocity function
% pause(sqrt(vx(k)^2+vy(k)^2+vz(k)^2));
endfor
次要注意事项:修改完该功能后,您需要强制Octave重新加载as it won't do this by default。您可以重新启动,或者更好地使用clear comet
和clear comet3
。然后,下次调用这些函数时,它们的定义将被刷新。
答案 1 :(得分:1)
当然不是最漂亮的,但这些是您需要对代码进行的第一次更改,以便做一些接近您想要的事情。
t = 0:0.1:10*pi;
z = linspace (1, 0, numel (t));
for ii=1:length(t)
plot3 (z(ii)*sin(t(ii)),z(ii)*cos(t(ii)), z(ii));
hold on
pause (.00001)
end
答案 2 :(得分:1)
以下似乎适用于Octave 3.6.2
t = 0:0.1:10*pi;
r = linspace (0, 1, numel (t));
z = linspace (0, 1, numel (t));
figure
axis([-1 1 -1 1 0 1])
hold on
for ii=1:length(r)
plot3 (r(ii)*sin(t(ii)), r(ii)*cos(t(ii)), z(ii),'*');
pause (.001)
end
答案 3 :(得分:0)
这不是轨迹解,但这是旋转的龙卷风。
phi = linspace(0, 10*pi, 300);
r = linspace (0, 1, 300);
z = linspace (0, 1, 300);
s = 100; %speed of turning
for t = 0:0.01:10 %t is time
plot3 (r.*sin(phi+t*s), r.*cos(phi+t*s), z);
pause(0.01)
end