java - 角速度和计算问题

标签 java vector simulation physics torque

所以,我的问题是,一旦形状获得大量角动量(任何视觉上明显的东西),碰撞就不再有效。它会碰撞、减速,但不会按照弹性要求反弹,也不会一次性“脉冲”,而是逐渐减速直至停滞。

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);
    }
}

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

最佳答案

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

vap1 = va1 + ωa1 × rap

其中 rap 是从质心到物体 a 上的点 p 的 vector ,如果这是您使用的,那么 rap 不是 p 处的切线,而是您希望您的 t = (p in world) - (CM世界).

关于java - 角速度和计算问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21962417/

相关文章:

simulation - AnyLogic Attractor 奇怪的行为

algorithm - Netlogo,创建避障算法

vhdl - VHDL 包 'IEEE.std_logic_arith' 是否随 ghdl 一起提供?

java - 如何将 int 转换为 char[] 以显示时间?

java - Android 中事件监听器的超时检测

java - 我们应该在java源代码中存储日语/法语和其他非ASCII字符吗?

arrays - 在 Matlab 中过滤数组/向量

java - JUnit hamcrest 长比较

c++ - vector 中的C++唯一值?

C++ 初始化 std::vector<std::unique_ptr<AbstractClass>>