首先是一个小背景,所以希望我更容易理解我想要做的事情:
我正在计算粒子对光子的散射。到目前为止,这一部分一切正常。但是为了可视化结果,我想要做以下事情:我展示了一个被击中的三维粒子'通过光子。光子由正弦波表示,它们首先直接传播到它们消失的粒子(这部分工作正常)。在同一时刻,当第一个光子的波浪进入'粒子,一个新的,分散的(意思是在任意三维方向上旋转)波必须出现。这也很好,但一次只能用于一个散射波。为此,我将plot3函数与set函数结合使用,以更新for循环中的wave位置。
但我想要的是以下内容:而#34; wavetrain" n波进入粒子,n散射波应该离开粒子,随着前一波模式变得完全可见,下一个开始出现。所以我看到越来越多的正弦波从粒子中飞出。每个在不同的方向上具有不同的x,y和z增量。
问题是每个散射波在x,y和z方向上具有不同的速度。因此,对于每个波,我需要一个循环来更新每个时间步的位置。此外,'设置'只允许我更新plot3函数的矢量数据,所以一次只能更新一个光子波的数据。
我完全坚持这个问题。所以任何新的意见或建议都受到高度赞赏:)
我知道附加的代码不是最短的,但这是我能得到的最短代码,同时仍能正确显示所有内容。目前代码工作正常,但散射波只能一次显示一个(发生在"发散射波" - 部分靠近底部)。我已经尝试了几种不同的方式,但我总是变得更糟......:/
clc
clear all
close all
%-------------------------------------------------------
%Variablen für Animationslänge und Scatter-Frequenz
%-------------------------------------------------------
%Anzahl der Photonen (hat direkten Einfluss auf Animationslänge)
Photons = 3;
%-------------------------------------------------------
%Background Photowand
%-------------------------------------------------------
a=1.0;
x=-5:0.01:0;
background(1,:) = cosh(x);
for i =1:80
Background(i,:) = background(:);
end
%--------------------------------------------------------
%Wave Pattern
%--------------------------------------------------------
y_w = (-1*pi:0.01:1*pi);
x_w = 40*ones(length(y_w),1);
x_w(1:length(y_w)) = 0.5*(sin(9*y_w)+sin(10*y_w));
z_w = zeros(length(y_w),1);
xyz_wave = [x_w,y_w',z_w];
%Rotationswinkel für korrekte Darstellung innerhalb des Plots
rotw = 90;
%Rotationsmatrix um Y-Achse
R1 = [cosd(rotw) 0 sind(rotw) ; 0 1 0; -sind(rotw) 0 cosd(rotw)];
%Rotation um X-Achse
xyz_waveR=xyz_wave*R1;
%Matrix wieder aufspalten in einzelne Vectoren
x_w1 = xyz_waveR(:,1);
y_w1 = xyz_waveR(:,2);
z_w1 = xyz_waveR(:,3);
%Abhängig von der Anzahl der Photonen wird die Eingangswelle um eine
%weitere Welle verlängert -> Vektor x_w1 wird kopiert und hinten angefügt
y_w2 = reshape(repmat(y_w1',1,Photons)',size(y_w1',1)*1,[]) ;
x_w2 = reshape(repmat(x_w1',1,Photons)',size(x_w1',1)*1,[]) ;
z_w2 = reshape(repmat(z_w1',1,Photons)',size(z_w1',1)*1,[]) ;
d = linspace(-pi*Photons,0,length(y_w2));
%--------------------------------------------------
%coordinates of scatterd photons
x_2r = [0.2823;-0.2565;0.0147];
y_2r = [0.5272; 0.3008; -0.4846];
z_2r = [-0.0756; -0.1863; -0.0930];
%Austrittsvektor wird zunächst mit NaN initialisiert um später mit
%realen Werten zu füllen
x_2rout2(1:length(x_w1),1:Photons)=NaN;
y_2rout2(1:length(x_w1),1:Photons)=NaN;
z_2rout2(1:length(x_w1),1:Photons)=NaN;
for w=1:Photons
%Calculation of the rotation angles for the scattered wave
dx(w) = x_2r(w);
dy(w) = y_2r(w);
dz(w) = z_2r(w);
hyp1(w) = sqrt((dy(w)^2)+(dx(w)^2));
hyp2(w) = sqrt((hyp1(w)^2)+(dz(w)^2));
alpha(w) = pi-acos(dy(w)/hyp1(w));
beta(w) = acos(hyp1(w)/hyp2(w));
%correction of the scattered angles for the rotation of the wave
%pattern
if x_2r(w) >=0
alpha(w)=pi-alpha(w);
end
if y_2r(w) >=0 && z_2r(w) <=0
beta(w)=beta(w)+pi;
end
if y_2r(w) <=0 && z_2r(w) >=0
beta(w)=beta(w)+pi;
end
if x_2r(w) >=0 && y_2r(w) >=0 && z_2r(w) >=0
beta(w)=pi-beta(w);
end
if x_2r(w) >=0 && y_2r(w) <=0 && z_2r(w) >=0
beta(w)=pi-beta(w)+pi;
end
if x_2r(w) <=0 && y_2r(w) >=0 && z_2r(w) <=0
beta(w)=pi-beta(w);
end
if x_2r(w) <=0 && y_2r(w) <=0 && z_2r(w) <=0
beta(w)=-beta(w);
end
if x_2r(w) >=0 && y_2r(w) <=0 && z_2r(w) <=0
beta(w)=beta(w)+pi;
end
if x_2r(w) <=0 && y_2r(w) <=0 && z_2r(w) >=0
beta(w)=beta(w)+pi;
end
%values used for the shift of the starting position of the scattered
%wave
dxx(w)=sin(alpha(w))*pi;
dyy(w)=cos(alpha(w))*pi;
dzz(w)=sin(pi-beta(w))*pi;
%Rotation of the scatterd wave
R_x = [1 0 0; 0 cos(beta(w)) -sin(beta(w)); 0 sin(beta(w)) cos(beta(w))];
R_z = [cos(alpha(w)) -sin(alpha(w)) 0; sin(alpha(w)) cos(alpha(w)) 0; 0 0 1 ];
xyz_wave_1 = xyz_waveR*R_x;
xyz_wave_2 = xyz_wave_1*R_z;
%Shift of the starting point of the scattered wave based on the rotation
if x_2r(w) >= 0
x_2rout(:,w) = xyz_wave_2(:,1)-abs(dxx(w));
else
x_2rout(:,w) = xyz_wave_2(:,1)+abs(dxx(w));
end
if y_2r(w) >= 0
y_2rout(:,w) = xyz_wave_2(:,2)-abs(dyy(w));
else
y_2rout(:,w) = xyz_wave_2(:,2)+abs(dyy(w));
end
if z_2r(w) >= 0
z_2rout(:,w) = xyz_wave_2(:,3)-abs(dzz(w));
else
z_2rout(:,w) = xyz_wave_2(:,3)+abs(dzz(w));
end
if x_2r(w)>=0 && y_2r(w)>=0 && z_2r(w)<=0
x_2rout(:,w) = xyz_wave_2(:,1)-abs(dxx(w));
y_2rout(:,w) = xyz_wave_2(:,2)-abs(dyy(w))*0.5;
z_2rout(:,w) = xyz_wave_2(:,3)+abs(dzz(w));
end
if x_2r(w)<=0 && y_2r(w)<=0 && z_2r(w)>=0
x_2rout(:,w) = xyz_wave_2(:,1)+abs(dxx(w));
y_2rout(:,w) = xyz_wave_2(:,2)+abs(dyy(w))*0.5;
z_2rout(:,w) = xyz_wave_2(:,3)-abs(dzz(w));
end
%Adding the actual position of the particle to the photon wave
x_2rout(:,w) = x_2rout(:,w) + 300;
y_2rout(:,w) = y_2rout(:,w) + 30;
z_2rout(:,w) = z_2rout(:,w) + 30;
%scalefunction
if abs(dy(w)) >= 0.8
dkk(w) = 11;
elseif abs(dy(w)) >= 0.95
dkk(w) = 12;
elseif abs(dy(w)) <= 0.3
dkk(w) = 7;
elseif abs(dy(w)) <= 0.5
dkk(w) = 8;
else
dkk(w) = 10;
end
end
%-------------------------------------------
%Partikel
%-------------------------------------------
[xs,ys,zs]=sphere(40);
%-------------------------------------------
%Plot
%-------------------------------------------
h_f=figure('color','w');
maximize(h_f);
Ax1=axes;
h_surf = surf(Background,'edgecolor','none','facelighting','gouraud','ambientstrength',0.1);
view(90,0)
colormap(Ax1,gray);
zeta = 0.7;
brighten(zeta)
camlight right
axis(Ax1,[0 400, 10 75, 2 62])
camzoom(Ax1,2);
axis off
hold on
%----dummyPlots for the wave patterns--------
h_nan = plot3(NaN,NaN,NaN,'LineWidth',1,'color','r');
h_nan2 = plot3(NaN,NaN,NaN,'LineWidth',1,'color','r');
%----Particle--------------------------
h_surf3 = surf(300+xs,30+ys,30+zs);
set(h_surf3,'EdgeColor','none','facecolor','g','facelighting','gouraud','ambientstrength',0.5)
%--------------------------------------
%Zusätzliche Variablen
q = 1;
qq = 1;
dk = 6;
%----------------------
for i = 1 : Photons
pp = 1;
set(h_nan2,'visible','on')
for k = 1:dk:length(x_w)
vec=ceil((length(x_w2)/(Photons*2*pi))*(0.1*dk));
if d(length(d))+0.1*k <= 30 && i==1
set(h_nan,'XData',300+x_w2,'YData',d+0.1*k,'ZData',30+z_w2);
elseif d(length(d))+0.1*k >= 30 && i == 1 && vec*2*q <= length(x_w2);
%let the incomming wave disapear
x_w2(length(x_w2)-vec*2*q:length(x_w2))=NaN;
y_w2(length(x_w2)-vec*2*q:length(x_w2))=NaN;
z_w2(length(x_w2)-vec*2*q:length(x_w2))=NaN;
set(h_nan,'XData',300+x_w2,'YData',d+0.1*k,'ZData',30+z_w2);
q = q+1;
end
if d(length(d))+0.1*k >= 30 && dkk(i)*pp*dk <= length(x_w)
%----------------------------------------------------------------
%----------------------------------------------------------------
%emitting of scattered wave
x_2rout2(1:1+dkk(i)*pp*dk,i)=x_2rout(1:1+dkk(i)*pp*dk,i);
y_2rout2(1:1+dkk(i)*pp*dk,i)=y_2rout(1:1+dkk(i)*pp*dk,i);
z_2rout2(1:1+dkk(i)*pp*dk,i)=z_2rout(1:1+dkk(i)*pp*dk,i);
set(h_nan2,'XData',x_2rout2(:,i)+dx(i)*pp,'YData',y_2rout2(:,i)+dy(i)*pp,'ZData',z_2rout2(:,i)+dz(i)*pp);
pp = pp + 1;
qq = pp;
else
set(h_nan2,'XData',x_2rout2(:,i)+dx(i)*qq,'YData',y_2rout2(:,i)+dy(i)*qq,'ZData',z_2rout2(:,i)+dz(i)*qq);
qq = qq + 3;
end
%---------------------------------------------------------------
%---------------------------------------------------------------
drawnow
end
%Ausblenden der Eingangswelle
set(h_nan2,'visible','off');
end