Search code examples
javascriptphysicsphysicsjs

Why gravity acceleration is 0.0004 in PhysicsJS?


Or, perhaps, better, what does it mean?

What the units are supposed be?

If I'm trying to simulate friction against the "background", like this:

return this
    .velocityDirection
    .mult(mu * this.mass * g)
    .negate();

I expect to use g as 9.80665 m/s^2. It was working this way before PhysicsJS:

var
    frictionForce;
    frictionForce = vec2.create();
    vec2.scale(
        frictionForce,
        vec2.negate(
            frictionForce,
            this.velocityDirection
        ),
        mu * this.mass * g
    );
return frictionForce;

Was using glMatrix for my linear algebra.

I was considering mass in kilograms and forces in newtons (etc) but in PhysicsJS it doesn't seem to work like that. (For example: if I have a circle body with radius 1, it's 1 what? Cause it'll make difference when I have to use this value for something else, and when "converting" it to pixels on the screen)

Now that I'm using a physics library I feel like I'm missing some of the physics...

I Hope someone can point me in the right direction to understand it better. I'm going through the API Docs right now and learning a lot but not I'm finding the answers I'm wishing for.

UPDATE

I received a very straightforward answer. This is just to let anyone interested to know what I did then...

Thanks to Jasper and dandelany I came to understand how some of PhysicsJS works much much better. To achieve my "dream" of using inputs in newtons, metres per second squared (etc) in PhysicsJS (and also have configurable pixels per metre ratio) I decided to create another integrator.

It's just a slight variation of the original (and default) verlet integrator. I explain it, more or less, at this (crude) article Metres, Seconds and Newtons in PhysicsJS


Solution

  • The units are pixels for distance, and milliseconds for time.

    So the acceleration is 0.0004 pixels/ms/ms

    Using meters doesn't make sense for a variety of reasons. The number of pixels per inch changes depending on device. Also, even if you did the conversion, an acceleration of 9.8 m/s/s would appear to be really fast because usually computer simulations want to give the appearance of looking at it from a distance... so you wouldn't want a meter on the screen to correspond to a meter in the simulation.