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
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
Share Improve this question edited Jun 11, 2014 at 21:39 slacktracer asked May 16, 2014 at 21:04 slacktracerslacktracer 6,3066 gold badges30 silver badges33 bronze badges 2- Probably just a value that "works". Treating pixels as real world units is tricky, especially in a game. Imagine "1 pixel = 1 ft" -- how much must this gravity constant be in pixels/sec² to fall a certain distance in a reasonable amount of time? Easier just to try different values until it appears right :-) – Jongware Commented May 16, 2014 at 21:35
- @Jongware wow... I really don't want to believe it. =P Previously I was handling the movement by myself and was "using" the usual units (at least, relative to each other). I just set 1 metre equal 50 pixels and everything worked out just fine. But at any time I could adjust this relation manually. And then I could simulate real forces with realistic values. As Burak Kanber does (burakkanber./blog/…)... I ain't giving up yet. =) – slacktracer Commented May 16, 2014 at 22:53
3 Answers
Reset to default 6The 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 puter 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.
Apparently I can't ment on posts yet so here's a follow-up to Jasper's answer, since you asked for tips on making the conversion:
Jasper gives the units as 0.0004 px/ms/ms
(or px/ms^2). Knowing the units makes this conversion pretty straightforward using unit cancellation. First we convert that figure to px/s^2:
0.0004 px/ms^2 * 1000 ms/s * 1000 ms/s = 400 px/s^2
Since we know that gravity on Earth is ~9.8 m/s^2
, this means that the default value is simulating a scale of:
400 px/s^2 * (1/9.8) s^2/m ~= 41 px/m
So with the default setting, PhysicsJS is simulating a world where a meter is 41 pixels long. If we use your example where "a 180 centimetres person is 50 pixels tall", then we are converting to a scale of:
50px / 0.180m ~= 278px/m
Convert this back to px/ms^2 with an acceleration of 9.8 m/s^2 and you get:
278 px/m * 9.8 m/s^2 * (1/1000) s/ms * (1/1000) s/ms ~= 0.00272 px/ms^2
So, to simulate a world where a 180cm person is 50px tall, you'd use 0.00272
for the PhysicsJS y-acceleration parameter.
From PhysicsJS Basic Usage - Behaviors
// add some gravity
var gravity = Physics.behavior('constant-acceleration', {
acc: { x : 0, y: 0.0004 } // this is the default
});
You have control over how gravity works, but it doesn't seem to provide a unit reference.