簡體   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