JavaScript physics

I made a very basic physics demo in JavaScript to practice using the MooTools library. It uses Verlet integration as outlined in Thomas Jakobsen’s paper.

To try out the demo, go to http://doswa.com/projects/physics_js/

Chain of particles attached by joints

Chain of particles attached by joints

This entry was posted in Physics, Programming. Bookmark the permalink.

6 Responses to JavaScript physics

  1. Pingback: Chain | Doswa

  2. Pingback: Chain | Doswa

  3. nniico says:

    Great demo, but what about collisions, frictions, etc. ? Do you have a more complete engine?

  4. David says:

    No, but check out Box2DJS – http://box2d-js.sourceforge.net/. It’s a full physics engine rather than just a demo.

  5. Ben says:

    Great work. Its missing self-collision though. I’m just mentioning this because it looks a bit weird without it.

  6. David says:

    Collisions would actually be quite easy to implement for this, since it uses Verlet integration. Apply a basic circle-circle collision test, then just modify the particles’ positions so they’re no longer overlapping.

    Keep in mind conservation of momentum when modifying the positions. Verlet integration works by implicitly keeping track of the velocity by holding on to the previous position (i.e. v = x - x*, where x* is the previous position), so momentum would be conserved like \Delta (m_1 (x_1 - x_1*)) + \Delta (m_2 (x_2 - x_2*)) = 0.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">