Live data from Hacker News

Verlet-js - Open source dynamic body physics engine

subprotocol.com

41–50 of 57 posts

Re: Verlet-js - Open source dynamic body physics engine

#41
You should make a benchmarking script to track speed over time. I've written probably 10 different Verlet engines in JavaScript, and the overhead of JavaScript's dynamic nature can be very palpable in the simulations.

For my most recent attempt at something speedy, here's some source code making use of typed arrays and doing away with objects completely. The speed improvement is good, but maybe the maintainability suffers a little (press space to create blob): https://c9.io/blixt/blob/workspace/index.html

Note that the particle-line collision is currently inefficient, so it slows down the simulation a lot more than it should.

Re: Verlet-js - Open source dynamic body physics engine

#42
post #37

Earlier quoted context omitted.

This is a really great point. Abstracting it away shouldn't be bad, and it is possible to extend by vec2 implementation to 3d. After I finish my next batch of examples I will venture down this path. Thank you for the feedback!

There is a physics engine for threejs- it's somewhere on their demo page. I'm actually working on a physics engine as well- I'm willing to help you extend it in whatever direction. A question, Why did you chose Verlet integration? I know it's great for particles but I always had issues trying to do angular mechanics.

Great question- I was reading about verlet integration and started doing some coding to play with it, and I just kept on going with it. Would love some help with it! First thing I would like to do is abstract out canvas.

Re: Verlet-js - Open source dynamic body physics engine

#44
post #37

Earlier quoted context omitted.

This is a really great point. Abstracting it away shouldn't be bad, and it is possible to extend by vec2 implementation to 3d. After I finish my next batch of examples I will venture down this path. Thank you for the feedback!

There is a physics engine for threejs- it's somewhere on their demo page. I'm actually working on a physics engine as well- I'm willing to help you extend it in whatever direction. A question, Why did you chose Verlet integration? I know it's great for particles but I always had issues trying to do angular mechanics.

Are you thinking of Physijs [0], which is made to work well with ThreeJS? Its a wrapper around Ammojs for ThreeJS.

It does look good and integrates well, but to be honest ThreeJS is so mature and battle tested with multiple renderers (canvas, webgl etc) that when building a physics engine, I really think it would be better to spend ones dev time on the physics and not waste* time reimplementing a portion of ThreeJS.

[0]: http://chandlerprall.github.io/Physijs/

*Obviously not actually 'wasted' time, hacking is great even just for the sake of it - but I'm sure you know what I mean.

Re: Verlet-js - Open source dynamic body physics engine

#45

Awesome! Thanks for sharing. It's amazing what you can do inside the browser these days. Any thoughts of integrating it with SVG? SVG is super useful for drawing and manipulating shapes in the browser.

SVG is usually much slower due to it's DOM representation, not a good fit for heavy animations.

Re: Verlet-js - Open source dynamic body physics engine

#46

Hi HN. I recently open sourced a verlet physics engine that I wrote for fun. Four example experiments are in there so far. I have a few other experiment ideas in mind that I hope to get implemented soon. Anyways, it was a blast creating this and thought others might like to look/play with it too. Cheers

There seems to be some numerical instability in the rotation. In the shapes demo, several of the shapes start spinning faster and faster when I pick them up. Particularly when I press the outside edge nodes into the center so that the shape sort of flips inside out, after that the shape just spins continuously when it is in the air.

Another way to exhibit it is to take the center node of the wheel and press it against the wall. The whole shape will spin.

Re: Verlet-js - Open source dynamic body physics engine

#47
post #38

Earlier quoted context omitted.

Verlet integration uses an object's change in position at time t to determine the velocity for t+1- it is typically used for particles not full rigid bodies.

Verlet is incredibly stable and allows you to update the position of a mass directly (velocity, force, momentum are all implicit), making it very easy to work with if not very accurate. You can't emulate rigid bodies very well (shape matching kinda works), collision response and stacking is a pain in the ass.

I guess I'm still having trouble understanding where the complexities arise. I have no difficulty believing that they do arise, but I would like to understand how it happens if you're willing to take the time to explain.

I would think that rigid bodies -- either perfectly rigid or semi-rigid via springs & struts -- would not handle all that differently in verlet since force is explicit (typo on your part?) and a v/p estimate is available from the last position, albeit with a bit more phase lag than usual. Does the phase lag induce nasty oscillations or something?

Re: Verlet-js - Open source dynamic body physics engine

#50

Earlier quoted context omitted.

Verlet is incredibly stable and allows you to update the position of a mass directly (velocity, force, momentum are all implicit), making it very easy to work with if not very accurate. You can't emulate rigid bodies very well (shape matching kinda works), collision response and stacking is a pain in the ass.

I guess I'm still having trouble understanding where the complexities arise. I have no difficulty believing that they do arise, but I would like to understand how it happens if you're willing to take the time to explain. I would think that rigid bodies -- either perfectly rigid or semi-rigid via springs & struts -- would not handle all that differently in verlet since force is explicit (typo on your part?) and a v/p…

We can make semi-rigid bodies in verlet using strings are shape matching techniques, but the pressure needed to maintain shape necessarily interferes with stacking or any other kind of stable contact. Actually, their was a solution to this in a shape matching paper by Matthias [1] but I was never able to get it to work right.

I've played around a lot with Verlet, it is very powerful in certain cases...especially since you can just update the position of a mass directly (very easy to program, very mouse/touch input friendly). However, a rigid body physics engine is probably better for most game use cases.

[1] http://www.matthiasmueller.info/realtimephysics/

Post reply on HN