求助画的空间动态图,如何不保留之前的轨迹。

1 view (last 30 days)
jngxbfx
jngxbfx on 20 May 2023
Answered: hxdreng on 20 May 2023
本人画了一个空间的扫描轨迹,红色代表扫描的斜边,绿色为扫描的轨迹。现在求助如何始终只存在一条红色线,下面绿色的轨迹线保留。代码如下:
clear all;
clc;
close all;
w=8*pi;%角速度
v=10;%下落速度为10m/s
%下落高度 130-20
%探测角是30度
%斜距是150 75
%1!!!画动态螺旋曲线%%
%
z = peaks(0);
surf(z)
hold on
t=linspace(13,0,1000);
x=v*t.*cos(w*t);
y=v*t.*sin(w*t);
z=v*t;
h1=animatedline;
h2=animatedline('color', 'g');
h1.Color = 'r';
h1.LineWidth = 1.0;
h1.LineStyle = '-';
axis([-150,150,-150,150]);
title('扫描轨迹');
for i = 2:length(t)
% addpoints(h1,x(i),y(i),z(i));
a=[x(i),y(i),0];
quiver3(0,0,z(i),x(i),y(i),-z(i),0,'ShowArrowHead','off','Color','r');
addpoints(h2,x(i),y(i),0);
pause(0.02);
drawnow
%hold on;
end
%hold off;
附件上是目前的图,希望在扫描过程中始终只存在一条红色斜边。

Accepted Answer

hxdreng
hxdreng on 20 May 2023
仅供参考
clear all;
clc;
close all;
w=8*pi;%角速度
v=10;%下落速度为10m/s
%下落高度 130-20
%探测角是30度
%斜距是150 75
%1!!!画动态螺旋曲线%%
%
z = peaks(0);
surf(z)
hold on
t=linspace(13,0,1000);
x=v*t.*cos(w*t);
y=v*t.*sin(w*t);
z=v*t;
h1=animatedline;
h2=animatedline('color', 'g');
h1.Color = 'r';
h1.LineWidth = 1.0;
h1.LineStyle = '-';
axis([-150,150,-150,150]);
title('扫描轨迹');
for i = 2:length(t)
% addpoints(h1,x(i),y(i),z(i));
a=[x(i),y(i),0];
h(i)=quiver3(0,0,z(i),x(i),y(i),-z(i),0,'ShowArrowHead','off','Color','r');
delete(h(i-1))
addpoints(h2,x(i),y(i),0);
pause(0.02);
drawnow
end

More Answers (0)

Categories

Find more on 图形性能 in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!