
Physics Simulations - pablode
https://www.myphysicslab.com/
======
rivaldo
Awesome stuff! A few months back I found a double pendulum simulation in less
than 100 lines of JavaScript. It was a ton of fun to play around with the
code.

Code and explanation: [http://www.physicsandbox.com/projects/double-
pendulum.html](http://www.physicsandbox.com/projects/double-pendulum.html)

Demo: [http://www.physicsandbox.com/projects/double-pendulum-
sim.ht...](http://www.physicsandbox.com/projects/double-pendulum-sim.html)

~~~
evanb
For an accurate double pendulum you almost certainly need a symplectic
integrator---not just Euler's method---or risk numerical instabilities that
come from nonconservation of energy.

~~~
effie
An integrator that is symplectic or conserves energy isn't necessarily
accurate, especially if the dynamical system is chaotic. Can you recommend
particular algorithm that is accurate for pendulum or double pendulum?

------
nicois
When I selected the double spring and pulled back the outer mass, as I let go
the distance between the two masses went negative. This caused a runaway
effect, sending system energy towards infinity.

Cute but the models are not very robust

~~~
evanb
This can be fixed with a more reliable integrator, at the expense of
computational speed.

------
tapirl
cool! Included here: [https://www.tapirgames.com/blog/open-source-physics-
engines](https://www.tapirgames.com/blog/open-source-physics-engines)

~~~
philipov
These all look like physics engines for graphics rendering. They all say 2d or
3d, and that means they surely can't handle concepts like relativistic
spacetime.

Do you know of any libraries for doing 'backend' physical simulations, such as
calculating scattering amplitudes, making projections of spacetime models onto
either space-like or time-like slices, and, especially, using tensor networks
for modelling condensed matter interactions?

~~~
fwilliams
Writing a general engine to do all these things is likely not a reasonable
thing to do.

Complicated dynamical systems usually involve solving PDEs and for that you
need to discretize your domain. How you choose to do so will drastically
affect the numerical properties of your simulation. Most "real-physics"
simulators tend to be specialized to a given task or even a given domain (for
example simulating heat diffusion in an engine part). There's a whole
literature on finite element methods to simulate various physical phenomena
though it can be quite dense.

The generic game physics engines use very simple models of mechanics and allow
for numerical issues (e.g. by using finite differences) in exchange for being
real-time. If you're looking to simulate more advanced physical phenomena for
a game, you're going to have to make similar trade-offs and will have to
choose which ones make for the best gameplay.

~~~
electricslpnsld
> The generic game physics engines use very simple models of mechanics and
> allow for numerical issues (e.g. by using finite differences)

Most modern game physics engines aren't actually discretizing an ODE or a PDE,
at this point. The current standard techniques (see Nvidia's PhysX, for
example) are instead solving something that look like a constraint
satisfaction problem but gives force-like effects. You don't even get
consistency under refinement with these methods, but they are cheap, and
importantly, stable when terminated early (to remain under strict time budgets
required of game based physics).

~~~
fwilliams
Interesting. So are these minimizing some constrained energy based on the
physical properties and current state of whatever you're trying to simulate?
If so, I don't quite understand how you avoid solving (or approximating) a
PDE/ODE. My research is mostly in meshing and I'm not familiar with real-time
simulation stuff. Do you have a link to a good paper on the topic?

~~~
electricslpnsld
Check out 'Position Based Dynamics' by Matthias Mueller, it was the first
paper on the topic.

~~~
maccard
Most games aren’t using anything remotely near as sophisticated as that. Most
games use rigid body simulations, and while the details of each implementation
is different, most of them work in a similar way. The common method in open
source engines is a projected gauss Seidel [0] which is used in bullet
physics. Most other engines (PhysX and Havok) are to the best of my knowledge
using something very similar.

[0]
[http://www.bulletphysics.com/ftp/pub/test/physics/papers/Ite...](http://www.bulletphysics.com/ftp/pub/test/physics/papers/IterativeDynamics.pdf)

~~~
electricslpnsld
> Most other engines (PhysX and Havok) are to the best of my knowledge using
> something very similar.

PhysX _is_ position based dynamics. The Mueller guy who wrote that paper was a
Co-founder of PhysX (back when it was NovodeX, then purchased by Ageia, then
purchased by Nvidia) and is now a lead researcher at Nvidia. [1]

> The common method in open source engines is a projected gauss Seidel [0]
> which is used in bullet physics.

PGS is just the numerical method that Bullet uses to solve for the collision
impulses between the rigid bodies (there are tons of other possible methods,
Nvidia again had a cool paper a few years back, there are also global
approaches with better convergence, etc). This is solving a so-called 'Contact
Dynamics' contact model [2], which originates in the work of French
mechanicians in the 70s and 80s.

Actually, if op is interested in PDEs in games, check out 'Digital Molecular
Matter' [3]. It was used in some Star Wars games, iirc. It is a pretty
straightforward Lagrangian discretization (linear shape functions on tets) of
a linearized hyperelastic energy density. They added a simple fracture model
on top which allowed for cool destruction effects in games.

[1] [http://matthias-mueller-fischer.ch](http://matthias-mueller-fischer.ch)
[2]
[https://en.wikipedia.org/wiki/Contact_dynamics](https://en.wikipedia.org/wiki/Contact_dynamics)
[3]
[https://en.wikipedia.org/wiki/Digital_Molecular_Matter](https://en.wikipedia.org/wiki/Digital_Molecular_Matter)

~~~
xchip
Great answer!

------
xchip
Here is my physics engine! (Works in your browser too!)

[http://htmlpreview.github.io/?https://github.com/aguaviva/Ph...](http://htmlpreview.github.io/?https://github.com/aguaviva/Physics/blob/master/Friction.html)

------
electricslpnsld
Very cool! Would be fun to have some implicit integrators to play with, too.
And visualizations of the symplectic form.

