繁体   English   中英

Matlab上的3D碰撞

[英]3d collision on 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

如果有人帮助我,我将非常感激。 我已经尝试解决了数周,但没有成功。

我可以为您提供一些“建议”:

  • 问题很复杂,您可能会从一个二维场景开始,该场景只有很少的粒子和一个正方形或一个五边形(而不是球体)
  • 考虑elastic collision
  • 您应该给粒子一个质量和一个速度(要在其X和Y分量上分解)
  • 您应该添加一个相对于仿真时间进行迭代的外部循环(每次迭代t=t+dt
  • 在每次迭代中,计算粒子的新位置
  • 可以相对于两个粒子之间的最小距离来定义碰撞条件(看来您已经完成)
  • 而不是通过点定义球体(或在简化的情况下为正方形),而是考虑一组网格(例如足球)并评估相对于它们的距离
  • 要确定碰撞后粒子的新方向,请考虑速度矢量的组成:您可以在Internet上轻松找到公式(例如, http//bolvan.ph.utexas.edu/~vadim/Classes/2014s/ collisions.pdf

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

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM