0

所以,我的问题是,一旦一个形状获得了大量的角动量(任何视觉上明显的东西),那么碰撞就不再起作用了。它发生碰撞、减速,但不会像弹性一样反弹,也不会一次“冲动”,而是逐渐减速直到停滞。

public Vec2 getVelocityAt(Vec2 p) {
    return getLinearVelocity().add(new Vec2(-getAngularVelocity() * p.getY(), getAngularVelocity() * p.getX()));
}

我很确定这个问题与上面的代码直接相关,我在这里遵循方程式:http ://www.myphysicslab.com/collision.html

public boolean checkBounds() {
    if(bX1 == bX2 || bY1 == bY2) {
        return false;
    }
    double xa = 0D;
    double ya = 0D;
    int a = 0;
    boolean hC = false;
    double xn = 0D;
    double yn = 0D;
    for(double[] vertex : this.getShape().getVerticies()) {
        if(vertex[0] >= bX2) {
            xa += vertex[0];
            ya += vertex[1];
            a++;
            hC = true;
            xn -= 1D;
        }
        if(vertex[0] <= bX1) {
            xa += vertex[0];
            ya += vertex[1];
            a++;
            hC = true;
            xn += 1D;
        }
        if(vertex[1] >= bY2) {
            xa += vertex[0];
            ya += vertex[1];
            a++;
            hC = true;
            yn -= 1D;
        }
        if(vertex[1] <= bY1) {
            xa += vertex[0];
            ya += vertex[1];
            a++;
            hC = true;
            yn += 1D;
        }
    }
    if(hC) {
        Vec2 n = new Vec2(xn, yn).uscale();
        Vec2 cp = new Vec2(xa / a, ya / a);
        Vec2 rap = cp.sub(getShape().getCM());
        Vec2 va = getVelocityAt(rap);
        Vec2 rva = va;
        Vec2 rvb = Vec2.ZERO_VEC.sub(va);
        double pj = -(1D + getElasticity()) * rva.dot(n);
        double j = pj / (1 / getShape().getMass() + Math.pow(rap.cross(n), 2D) / getShape().getMass());
        applyForce(new AppliedForce(n.scale(j), rap, getShape().getMass()));
    }
    return hC;
}

public void applyForce(AppliedForce... f) {
    for(AppliedForce vec : f) {
        Vec2 a = vec.getForce().divide(getShape().getMass());
        applyLinearAcceleration(a);
        double aa = a.relativeCosine(getShape().getTangent(vec.getOffsetCM())) * a.getMagnitude() / getShape().getMass();
        applyAngularAcceleration(aa);
    }
}

如果没有角速度,则不会发生问题,并且角速度越高越明显。我认为点函数的速度是问题的根源,但不确定原因。我已经进行了调试,没有发现太多,我认为这是对数学的误解。有谁知道我做错了什么?

4

1 回答 1

2

我正在查看您链接到的页面的 2 维中刚体的碰撞物理部分中的第一个公式:

vap1 = va1 + ωa1 × rap

其中 rap 是从质心到身体 a 上的点 p 的向量,如果这是您使用的,那么 rap 不是 p 处的切线,而是您想要您的t = (p in world) - (CM in world).

于 2014-02-23T03:04:33.307 回答