News for hackers. Stuff that matters.
Re:Modeling Physics in Javascript: Gravity and Drag by Simucal on Saturday September 08, 2012 @12:06PM (#4493193)
I wrote something like this a couple years ago[1]. I also attempted to support ball-to-ball collisions. I rarely do any graphics type programming so this was a fun diversion.

However, the simulation would slow down considerably after adding a few dozen balls. This was largely due to the quadratic nature of my naive collision detection. In order to remedy the speed problems I implemented[2] a quadtree I found online to assist me in culling a lot of my expensive collision checks. The bounds of the quadtree sections will appear as you begin to add balls.

Unfortunately the quadtree wasn't the performance savior I expected it to be. I didn't notice a dramatic improvement in the number of balls I could support. I also introduced a bug with the quadtree version where certain collisions are missed entirely.

Perhaps I should revisit this simulation and see where I was off.

[1] - http://jsfiddle.net/simucal/RvA9w/33/

[2] - http://jsfiddle.net/simucal/RvA9w/

Re:Modeling Physics in Javascript: Gravity and Drag by mrhyperpenguin on Saturday September 08, 2012 @03:47PM (#4493792)
Instead of quadtrees take a look at spatial hashing[0]. It's more simple than quadtrees and the performance is similar if not better.

[0] http://www.gamedev.net/page/resources/_/technical/game-progr...

[deleted]
Re:Modeling Physics in Javascript: Gravity and Drag by bkanber on Saturday September 08, 2012 @01:40PM (#4493453)
Performance is great for me too, but when you have a ton of balls the collision detection fails. Probably just a bug in the quadtree. Otherwise, great performance!