Curved trajectory due to spin

Hi,

I am using JBox2D. I am trying to simulate the curved trajectory of a spinning ball as it travels through the air, say like a tennis or ping-pong ball. I've achieved this so far in the test bed by overriding the step method and applying the following code:

Code: Select all

    Vec2 curveImpulse = new Vec2();

    @Override
    public synchronized void step(TestbedSettings settings) {
        super.step(settings);

        if (ballBody.m_angularVelocity != 0) {
            Vec2.crossToOut(ballBody.m_angularVelocity * 0.0001F, ballBody.m_linearVelocity, curveImpulse);
            ballBody.applyLinearImpulse(curveImpulse, ballBody.m_sweep.c);
        }
    }


This appears to have the effect that i want, although i'm not sure that the physics is exactly right. More so, i wondered if there were a better way of implementing it. I'm using a FrictionJoint for the linear and angular friction, and thought it might be appropriate to add the code there (plus a new field to represent the hardcoded 0.0001F).

Any recommendations are welcome.

Regards,
Matthew
For the spin effect, that is probably as good as you can get. For drag/friction, you could also try setting linear damping and angular damping for the body instead of a friction joint, although I think the friction joint would be fine too.
Thanks irresistible force. BTW, is there much difference between applying an impulse vs a force? Would it be correct to say that an impulse is a single step thing, while a force is applied over multiple steps?
That's exactly right. Applying a small impulse every step is not really any different from applying a force.

Original thread: https://box2d.org/forum/viewtopic.php?t=9606