三维碰撞matlab



我正在开发一个这样的系统:我有一个球体,里面有许多分子。如果分子发生碰撞,它们的新方向需要重新计算,如果它们与球体壁发生碰撞,也需要重新计算。我已经有了两个矩阵:一个是所有粒子的坐标,另一个是球壁的坐标。这是我的部分算法。

% 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
如果有人帮助我,我会非常感激。

我只能给你一些"建议":

  • 这个问题很复杂,你可以从一个2D场景开始,有几个粒子和一个正方形或五边形(而不是一个球体)
  • 考虑elastic collision
  • 你应该给粒子一个质量和速度(要分解它的X和Y分量)
  • 你应该添加一个外部循环迭代相对于模拟时间(在每次迭代t=t+dt)
  • 在每次迭代时,计算粒子
  • 的新位置
  • 碰撞条件可以根据两个粒子之间的最小距离来定义(看起来你已经这样做了)
  • 考虑一组网格(如足球)并计算相对于它们的距离,而不是用点来定义球体(或者,在简化的情况下,正方形)
  • 要确定粒子的新方向,在碰撞之后,考虑速度矢量的组成:你可以很容易地在互联网上找到公式(例如http://bolvan.ph.utexas.edu/~vadim/Classes/2014s/collisions.pdf
  • )

一旦你有了一个稳定的二维解决方案,你就可以添加第三维。

最新更新