用matlab画小球沿空间螺旋线从上往下运动并能以下往上回到起点

如题所述

clc; clear; close all;

t = linspace(0, 20*pi, 500); % 曲线

r = 3; % 球半径
[x,y,z] = sphere; % 球

% 从上往下
figure;
for k = length(t):-1:1
plot3(t.*sin(t), t.*cos(t), t); % 画出 tsin(t),tcos(t),t 的曲线
axis([-100 100 -100 100 -20 80]);
grid on;
hold on;
mesh(r*x+t(k)*sin(t(k)), r*y+t(k)*cos(t(k)), r*z+t(k));
hold off;
if k == length(t)
pause(1); % 第1次出现停1秒
else
pause(0.001);
end
end

pause(0.5);

% 返回起点
for k = 1:length(t)
plot3(t.*sin(t), t.*cos(t), t); % 画出 tsin(t),tcos(t),t 的曲线
axis([-100 100 -100 100 -20 80]);
grid on;
hold on;
mesh(r*x+t(k)*sin(t(k)), r*y+t(k)*cos(t(k)), r*z+t(k));
hold off;
pause(0.001);
end

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答