确定撞击的相对速度?
我正在尝试找出一种方法来确定二维环境中物体与另一个物体碰撞的相对速度。
例如,如果一个物体以 (1,0) 移动,而另一个在其后面行进的物体以 (2,0) 与它碰撞,则相对于第一个物体的碰撞速度为 (1,0)。
我需要一种接受两个速度的方法,一个速度属于正在测量速度的物体,另一个属于撞击物体并返回相对速度。
I'm trying to figure out a way to determine the relative velocity of a body colliding with another in a 2D environment.
For example if one body is moving at (1,0) and another traveling behind it collides with it from behind at (2,0) the velocity of the impact relative to the first body was (1,0).
I need a method which takes in two velocities, one velocity belonging to the body the velocity is being measured against, and the other for the impacting body and return the relative velocity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯?当然,这应该只是向量 1 的分量 1 - 向量 2 的分量 1 和向量 1 的分量 2 - 向量 2 的分量 2?编写方法
事实上,Vector2 结构有一个减法方法,可以产生以下结果: vector2减去
ey? Surely this should be just component 1 of vector 1 -component 1 of vector 2 and component 2 of vector 1 - component 2 of vector 2? Write a method
In fact, the Vector2 structure has a subtract method that yields this result: vector2 subtract
我不知道 C# 中已有什么,但您将从包含物理的矢量库中受益。简单的向量库将确定相对速度,但如果您正在研究物理(例如粒子弹跳),您可能需要考虑粒子的质量并保持动量守恒(例如,当两个相同质量的速度为 (1,2) 和 ( -1,3) 互相撞击,在这种情况下,您将需要一个模拟每个粒子的质量、位置和速度的类(例如,模拟由原子组成的材料就是这样做的)。
I don't know what is already in C# but you will benefit from having a Vector library which includes physics. The simple vector libraries will determine relative velocities but if you are doing physics (e.g. particles bouncing) you may need to consider the masses of the particles and to conserve momentum (e.g. what happens when two equal masses with veclocity (1,2) and (-1,3) hit each other. In which case you will need a class which models the mass, position and velocity of every particle. (This is what is done in simulating material made of atoms, for example)