ฉันกำลังพัฒนาระบบเช่นนี้ ฉันมีทรงกลมที่มีโมเลกุลมากมายอยู่ข้างใน หากโมเลกุลชนกัน จะต้องคำนวณทิศทางใหม่อีกครั้ง รวมทั้งชนกับผนังทรงกลมด้วย
ฉันมีเมทริกซ์สองตัวอยู่แล้ว ตัวหนึ่งมีพิกัดของอนุภาคทั้งหมด และอีกตัวหนึ่งมีพิกัดของ ผนังของทรงกลม นี่คือส่วนหนึ่งของอัลกอริทึมของฉัน
% Coordinates of the wall of the sphere
theta=linspace(0, 2*pi, 25);
phi=linspace(0, pi, 25);
x_sph=r_sph.*cos(theta).*sin(phi);
y_sph=r_sph.*sin(theta).*sin(phi);
z_sph=r_sph.*cos(phi);
[x_sph' y_sph' z_sph'];
itmax=100
for it=(1:itmax);
for i3=1:500
for j3=1:500
if i3~=j3
dist1(i3,j3,it)=sqrt((balls_in_sphere(i3,1)-balls_in_sphere(j3,1))^2+(balls_in_sphere(i3,2)-balls_in_sphere(j3,2))^2+(balls_in_sphere(i3,3)-balls_in_sphere(j3,3))^2);
if dist1(i3,j3,it)<=d
%recalculate the new directions ???
end
end
end
for j3=1:25
dist2(i3,j3,it)=sqrt((balls_in_sphere(i3,1)-cs(j3,1)^2)+(balls_in_sphere(i3,2)-cs(j3,2)^2)+(balls_in_sphere(i3,3)-cs(j3,3)^2));
%comparative between the coordinates of the balls inside the sphere and the points of the sphere
if dist2(i3,j3,it)<=d
%if there is a collision, recalculate the directions ???
end
end
end
balls_in_sphere1=balls_in_sphere2;
end
ฉันจะขอบคุณมากถ้ามีคนช่วยฉัน ฉันพยายามแก้ไขมาหลายสัปดาห์ แต่ก็ไม่ประสบความสำเร็จ