模拟粒子运动的好方法是什么?
我正在尝试模拟以下情况:
- 10 个球在固定尺寸的区域中移动
- 每当两个或多个球进入 40m 的邻近范围时,我想要一个事件 我的想法是利用
具有不同属性的运动轨迹来引导球的运动,并研究每个球如何相互接触。有人可以建议一个好方法来做到这一点吗?
I am trying to simulate the following:
- 10 balls that are moving in an area of fixed dimensions
- Whenever two or more balls come into a proximity range of say 40m, I want an event
to be triggered
My idea is to utilize a movement trace with different properties to guide the movement of the balls and study how each of these balls come into contact with each other. Can someone suggest a good way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我怀疑您正在寻找的是碰撞检测和/或响应算法。您可能会发现这个问题和答案与您的几乎完全相同设想。为了更好地解释基础物理和数学,我发现这些 Chris Hecker 的文章非常有用。
I'm suspecting what you are looking for is collision detection and/or response algorithms. You might find this question and answer doing almost exactly the same as your scenario. For good explanation of underlying physics and math I find these old articles from Chris Hecker very useful.
对于物理(移动和碰撞),有开放动力学引擎,它具有与各种语言的绑定,包括 python。我个人没有使用过这个,但它已经在一些商业游戏中使用过。
For physics (moving and colliding), there's the Open Dynamics Engine which has bindings with various languages including python. I personally haven't used this but it has been used in a few commercial games.
在正常方法中,我们可以做的是......每次任何球的每次运动时,检查任何球是否与其他球碰撞。
然后我们可以通过保持每对球之间的安全距离变量来对此方法进行一些优化。安全距离是指两个球之间在碰撞之前的距离。如果这两个球移动了总安全距离,则无需检查它们是否发生碰撞,一旦它们的移动累积超过安全距离,那么我们只检查碰撞并计算安全距离以供下次检查。
例如,对于您的情况,如果两个球彼此相距 100 m,则安全距离为 60 m,因此我们不会检查碰撞,除非这两个球都移动 60 m 的距离。
这只是我的想法。其他人可以告诉我们更好的方法。
In a normal approach what we can do is... every time on every movement in any ball, check if any ball is colliding with any other ball.
Then we can put some optimization in this approach by keeping safe distance variable between every pair of balls. Safe distance means the distance between two balls, which is available before collision. If those two balls moves by that total safe distance, no need to check if they are colliding, once the accumulation of their movement is more than safe distance, then only we will check collision and calculate safe distance for next check.
For example for your case, if two balls are 100 m far from each other then safe distance is 60 m, so we will not check collision until unless both these balls move 60m distance.
this is just my thought. others can tell better approaches.