All those are great physics engines. Mine is just very simple and easy to understand, hopefully it inspires other people to get into the world of simulations.
In fact that was one of the reasons that compelled me do write my own, because physics engines looked to me like voodoo magic. Thanks for understanding my obsession with learning :)
To add to the list, the best physics engine I've seen (not for js games, for actual physics simulations to teach people physics) is this one: https://www.myphysicslab.com/
I'm with you, and I don't even find this particular example that interesting or accurate. You just re-run the same simulation over and over without any control of the initial or boundary conditions.
Fantastic, in fact I wrote because I had been trying to understand physics engines four a long time and it was super hard to follow the papers. I wrote it four learning my self and published it to help others not go through my frustration :)
If you want to look at precedence or what other people have done successfully in this space check out http://brm.io/matter-js/ matter JS. It's pretty sweet.
I don't mean to be rude, but if you don't know the term I'd put money on it not being deterministic. Especially if you're running in JavaScript on multiple browsers.
A single step that isn't consistent in behavior across every setup is enough to make the entire process non-deterministic.
The alternative is to treat the simulation as a series of immutable instants. Every step of the simulation is encapsulated and represented as a data structure. So the core loop would look something like nextState = advanceFrame(currentState) , where currentState is immutable and contains every piece of information needed to calculate nextState.
Then you can do whatever you want with that series of immutable instants. You might pass that data structure to a function for rendering, or for storing history, or whatever else. You might even do something clever like pass two consecutive steps into your rendering function, so you can calculate motion blur between them.
Treating each simulation step as an instance of a data structure means you decouple the simulation state and time from your program state and time. Novice programmers often use global variables to hold the state of a simulation or game, but there's a smarter way to do it. You insert a layer of abstraction between your program's control flow and the simulation's time flow.
Is this really a simulation if you can't modify any of the objects? For all we know, this could all be pre-calculated or pre-animated. Everything moves exactly the same way every time.
It moves differently in different browsers for me. And neither instance seems to actually make physical sense.
In Chrome, the fourth box from the top starts sliding when it hits the floor, pushing the box to the right clear off the floor box. Every box eventually slides along the floor and falls into the pit.
In Firefox, the fourth from the top stays put. It never pushes the box on the right, though all the rest eventually slide into the pit.
In Firefox Developer Edition everything happens faster than in regular Firefox, though they seem to end at the same result. I wonder why that is. Animation doesn't seem much faster.
I think the "neither instance seems to actually make physical sense" is due to a lack of friction.
Hey hey hey, let's not blame floating point here ;).
Floating point is completely deterministic (as you note by getting the same behavior every time you run the simulation in the browser). I'm looking at the js spec, and there shouldn't be any freedom in evaluating floating point expressions (but overly clever browser vendors may have ignored that and reordered them anyhow).
However, I do know for a fact that the implementations of the Math.sin and Math.cos functions are browser specific,
> does it have conservation of energy? Can you track total energy somehow?
You're going to need a geometric integrator for that, probably an energy-momentum integrator. In practice it is often better to conserve the symplectic form instead of energy, though, and you can show that for fixed time-steps you can't get all of energy/momentum/symplecticity at the same time (I haven't looked at this for a while, a student of the school of Marsden jump in if I'm saying anything wrong). Furthermore, these guarantees all require integrability...
My (ongoing) thesis is in the field of symplectic integrators.
I was asking about these simplified physics engines (in games, etc.) that are probably not deriving physical laws out of whole conservation- (or Noetherian symmetry-) cloth.
Very cool! Game rigid body engines (to my knowledge) usually use symplectic Euler (v^{n+1} = v^n + h M^{-1} F^n, q^{n+1} = q^n + h v^n) with a Moreau/Stewart-Trinkle velocity level discretization of non-penetration constraint (effectively impulses), usually lobbing off the quadratic velocity term (so no precession). These constraints are typically solved in a (projected) Gauss-Seidel fashion to horribly loose tolerances, with liberal post-stabilization thrown in. Outside of rigid bodies, for the most part in games, these days, you don't get 'simulations' that can be derived from a variational principle, but that are instead constraint satisfaction problems with some notion of momentum hacked in the side (see 'Position Based Dynamics', 'Shape Matching').
The movie folks have larger compute time budgets, and I've seen various geometric integrators used there. I know of at least one studio that uses implicit midpoint for thin shell simulation. The Cal-Tech influence has wormed its way into the graphics research world, at least, and you see some papers pop up there frequently looking at geometric integrators. This Danish guy (I'm forgetting his name) at Disney publishes papers every now and then on the topic.
It is surprisingly difficult to find a concrete explanation of symplecticity. It seems like https://en.m.wikipedia.org/wiki/Symplectic_integrator has links to all the relevant information, but even there the conserved quantity is given as a differential form dp /\ dq, which makes me wonder whether you can even compute it for individual points, or whether you have to integrate over the whole space.
this one shows how to solve a double/n pendulum, which is something that is not explained in detail anywhere. So if you want to learn how constraints work that should get you up to speed!
I think the word you were looking for was "friction". This certainly looks like a simulation that a physics professor would propose on a chalk board: "Ignoring friction for the purpose of this exercise..."
Of course it depends on what the goal of the program is, but something like this should offer user interactivity. By solving whatever is necessary (or faking it).
a) I know, that is still WIP :)
b) There is no friction, and as Newton's First Law states "an object will remain at rest or in uniform motion in a straight line unless acted upon by an external force" :)
Hey, again no offense meant. I just think the whole point of something like this is to mimic the real world. And after a couple of seconds my illusion is broken. Ps. It is cool, just needs to be cooler :)
Physics engines are like magic and it is pretty hard understand how the work even if you read the paper many times. Also physics engines are interesting not only because four the dynamics, but also for the way constraints are solved. There are many other problems were you could apply this same techniques. This JavaScript engine it's a couple of pages long, it's easy to understand and potentially could give you a new vision on how to solve problems. The reason why is uses do much CPU time is because the collision detection algorithm compares every single pair of objects, to speed up that part I'd need to add what is called a 'broad phase' but that would complicate the code and the point was to write clear code and leave the low hanging fruit for the reader.
Matter.js: http://brm.io/matter-js/
Cannon.js: http://www.cannonjs.org/
PhysicsJS: http://wellcaffeinated.net/PhysicsJS/
Box2DJS: http://box2d-js.sourceforge.net/ (Emscripten-compiled from flash)
p2: https://github.com/schteppe/p2.js
Ammo.js: https://github.com/kripken/ammo.js/ (Emscripten-compiled from C++)
JPE: https://github.com/colorhook/JPE
Oimo.js: https://github.com/lo-th/Oimo.js/
Planck.js: https://github.com/shakiba/planck.js