首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何求出两个碰撞刚体的速度?

如何求出两个碰撞刚体的速度?
EN

Stack Overflow用户
提问于 2015-08-07 16:38:28
回答 1查看 70关注 0票数 0

所以我要跳进一个物理引擎。目前对撞机是球体和平面。我发现碰撞的深度和正常的接触点很容易,但对于我的生命,我不能把我的头围绕着能量的分布。

这些物体包含一个对撞机,一个质量,一个力矢量(速度*质量),一个弹性值(0没有弹跳,1次完全反弹)和一个摩擦值(0滑香肠,1个动量吸血),我搜索到地狱和背部,所有的东西都得到了1D和2D的简化,但我根本无法适应3D。

编辑:,我试着跟随这个页面:http://www.plasmaphysics.org.uk/collision3d.htm。这看起来很简单,但出于某种原因,我仍然没有弹力,弹性为1。

我的执行情况如下:

代码语言:javascript
复制
var v = new vec3(
    (body.force.x + other.force.x) / totalMass,
    (body.force.y + other.force.y) / totalMass,
    (body.force.z + other.force.z) / totalMass
    );
body.force.set(
    ((velA.x - v.x) * elasticity + v.x) * body.mass,
    ((velA.y - v.y) * elasticity + v.y) * body.mass,
    ((velA.z - v.z) * elasticity + v.z) * body.mass
    );
other.force.set(
    ((velB.x - v.x) * elasticity + v.x) * other.mass,
    ((velB.y - v.y) * elasticity + v.y) * other.mass,
    ((velB.z - v.z) * elasticity + v.z) * other.mass
    );

关于弹性,我试着把两个身体的弹性相乘,得到它们的平均值;没有变化。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-08 16:27:59

因此,晚上睡一觉,思考一下,以及从N+物理解释页面上得到的巨大帮助--我把一些东西混在一起,虽然在物理上不一定准确,但为了调试,它被分成了许多变量,但我已经尽我最大的能力发表了评论。

代码语言:javascript
复制
    //we have detected a collision between A) body B) other
        //note: for the sake of making things easier to think about,
        //      anything moving into or along the collision normal is
        //      referred to as vertical, anything perpendicular to
        //      the collision normal, is referred to as horizontal.
    //minimum translation required to resolve the collision
var mta = collision.normal.clone().multiplyScalar(collision.length);
    //the total mass involved in the collision
var totalMass = body.mass + other.mass;
    //the ratio of the mass belonging to body
var ratioA = body.mass / totalMass;
    //the ratio of the mass belonging to other
var ratioB = other.mass / totalMass;
    //the average elasticity of the collision
var elasticity = (body.elasticity + other.elasticity) / 2.0;
    //the friction of the collision
        //note: average works, but low values have strong effects,
        //      it is easier to work with if they are multiplied
var friction = body.friction * other.friction;
    //the vertical force of body
var vertA = -body.force.clone().normalize().dot(collision.normal);
    //the horizontal force of body
var horrA = 1.0 - Math.abs(vertA);
    //the vertical force of other
var vertB = -other.force.clone().normalize().dot(collision.normal);
    //the horizontal force of other
var horrB = 1.0 - Math.abs(vertB);
    //the amount of force applied on body
var forceA = body.force.length();
    //the amount of force applied on other
var forceB = other.force.length();
    //the amount of vertical force applied on body
var vForceA = forceA * vertA;
    //the amount of vertical force applied on other
var vForceB = forceB * vertB;
    //the amount of horizontal force applied on body
var hForceA = forceA * horrA;
    //the amount of horizontal force applied on other
var hForceB = forceB * horrB;
    //the total vertical force of the collision
var verticalForce = (vForceA + vForceB) * elasticity;
    //remove all vertical force from body
    //resulting in a horizontal force vector
body.force.add(collision.normal.clone().multiplyScalar(forceA * vertA));
    //apply friction to the horizontal force vector of body
body.force.add(body.force.clone().normalize().multiplyScalar(-friction * hForceA * body.imass));
    //apply the new vertical force to body
body.force.add(collision.normal.clone().multiplyScalar(verticalForce * ratioA));
    //remove all vertical force from other
    //resulting in a horizontal force vector
other.force.add(collision.normal.clone().multiplyScalar(-forceB * vertB));
    //apply friction to the horizontal force vector of other
other.force.add(other.force.clone().normalize().multiplyScalar(-friction * hForceB * other.imass));
    //apply the new vertical force to other
other.force.add(collision.normal.clone().multiplyScalar(-verticalForce * ratioB));
    //resolve collision taking into consideration mass
body.transform.position.sub(mta.clone().multiplyScalar(ratioA));
other.transform.position.add(mta.clone().multiplyScalar(ratioB));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31882704

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档