A 2D Physics Simulator in JavaScript

Learning and science

physics simulation

SHOW HN2017

126points
62comments
#333of 2,242 in 2017
Top 15%of 2017 by points

How HN took it

DebatedReal support and real criticism

6 positive, 5 neutral or asking, 1 mixed, 11 critical, out of 23 comments about the project. Thread score -0.26.

Idea: 1 for, 5 againstPerformance: 1 for, 5 againstDocs: 2 for, 0 againstExecution: 0 for, 1 against

The thread, comment by comment

Each row is a top-level comment and its replies, in HN's order. Select a cell to open that comment on HN.

positive neutral or mixed critical about another commenter or something else the maker

What HN said

What people liked

  • Code fits on one page and is easy to understand

    From 1 comment
    • What's special about this simulation is that the entire code fits on one page, including linear algebra library:…
      ivan_ah on HN
  • Good for learning and teaching physics simulation

    From 2 comments
    • What's special about this simulation is that the entire code fits on one page, including linear algebra library:…
      ivan_ah on HN
    • Thanks, good show. Another one I like is http://physics.weber.edu/schroeder/html5/. See Newton's cannon etc.
      pdm55 on HN

Objections

  • No friction, so motion looks unrealistic

    From 3 comments
    • 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…
      SketchySeaBeast on HN
    • The only part missing? Physics... Somehow boxes slide along a flat floor with no deceleration until they fall off the screen
      dmitrygr on HN
    • 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…
      eric_h on HN
  • Not interactive; cannot modify objects

    From 2 comments
    • 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…
      dkonofalski on HN
    • Erm, no offense but: a) physics programs are supposed to offer interactivity. Else whats the point? b) the physics look unearthly
      laythea on HN
  • Non-deterministic or varies across browsers

    From 2 comments
    • 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…
      FroshKiller on HN
    • 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…
      reificator on HN
  • High CPU usage due to no broad phase collision detection

    From 2 comments
    • Out of curiosity: The chrome tab running the engine is using 55% of my CPU, an i7-4770K running at 3.5Ghz... Box2D with many more objects consumes 22%. Oimo, with a 3D rendering…
      danilocesar on HN
    • 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…
      xchip on HN

Requests

  • Add friction

    From 3 comments
    • Is there friction or non-zero restitution?
      santaclaus on HN
    • It doesn't take into account surface friction? Those boxes seem covered in soap to me.
      Aeolun on HN
    • 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…
      SketchySeaBeast on HN
  • Add user interaction such as mouse control

    From 2 comments
    • :D you are welcome to add objects, make the chain longer or change gravity... Having always the same animation helps debugging. But yeah I should have added the option to add a…
      xchip on HN
    • 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,…
      laythea on HN

Questions

  • Is the simulation deterministic?

    From 1 comment
  • Does it conserve energy?

    From 1 comment
    • This is where I show that I know nothing about physics engines: ... does it have conservation of energy? Can you track total energy somehow? ... does it obey approximately some…
      thanatropism on HN

Alternatives named

  • Matter.js

    From 2 comments
    • Why is this upvoted so much? In what way is it better than any of the existing JS physics engines? Matter.js: http://brm.io/matter-js/ Cannon.js: http://www.cannonjs.org/…
      olegkikin on HN
    • 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.
      ell0ell0 on HN
  • Box2D

    From 2 comments
    • Why is this upvoted so much? In what way is it better than any of the existing JS physics engines? Matter.js: http://brm.io/matter-js/ Cannon.js: http://www.cannonjs.org/…
      olegkikin on HN
    • Out of curiosity: The chrome tab running the engine is using 55% of my CPU, an i7-4770K running at 3.5Ghz... Box2D with many more objects consumes 22%. Oimo, with a 3D rendering…
      danilocesar on HN
  • Cannon.js

    From 1 comment
    • Why is this upvoted so much? In what way is it better than any of the existing JS physics engines? Matter.js: http://brm.io/matter-js/ Cannon.js: http://www.cannonjs.org/…
      olegkikin on HN
  • PhysicsJS

    From 1 comment
    • Why is this upvoted so much? In what way is it better than any of the existing JS physics engines? Matter.js: http://brm.io/matter-js/ Cannon.js: http://www.cannonjs.org/…
      olegkikin on HN
  • myphysicslab

    From 1 comment
    • 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/ PheT…
      ivan_ah on HN

Category, keywords, summaries and labels on this page were made by AI (Thread Reader v2) and not checked by hand. Each point links to the comments it came from.

Add a badge to your READMEShown on HackerShow
[![Shown on HackerShow](https://hackershow.org/badge.svg)](https://hackershow.org/show/14865184)