Settings

Theme

Show HN: Dyna-Kinematics – A 2D physics simulator with some unique features

github.com

78 points by diegomacario 6 years ago · 15 comments

Reader

diegomacarioOP 6 years ago

Hi everyone!

I'm the author of this project. I wrote it because I was very curious about physics simulation, and also because I wanted a reason to study a few libraries that I had never worked with like Qt.

In the readme I tried to explain all the details of how the simulator works. If you don't have time to read it, at least take a look at the GIFs in it. They showcase everything that the simulator can do.

  • jessedhillon 6 years ago

    There might be a really useful related application here. If I could set up a 2D scene to be simulated headlessly, apply forces programmatically, and then receive the x position of an actor as an output, then this could be useful for simulating complex UI behaviors.

    For example, recently I wanted to create a scrolling behavior with boundaries based on properties of the content. In this case, I wanted to draw a column of cards with a bit of tension to overcome before flipping to the next card.

    See this diagram: https://imgur.com/a/zVvwtEu

    If the viewport was a physical actor in a simulation, gliding along a track that I could generate based on the content, then the left edge of the actor could control the scrollTop or drive the translateY of the content, etc.

    Just wanted to share a possible application of your awesome work.

    • diegomacarioOP 6 years ago

      That's a really cool idea!

      It's funny that you mention this because when I simulated the blocks hitting the words "Dyna-Kinematics" for the title GIF I thought: "This is what graphic designers struggle to do manually. They spend hours animating things so that they look natural."

      If graphic designers had access to a physics simulator, they wouldn't have to do anything manually. They could just let the physics do the talking.

      I really love that idea, and I think it would sell.

  • rodrigosetti 6 years ago

    Diego, this is really amazing.

    The one gif where you throw a block into a stack reminds of some interesting property of the laws of classical mechanics: they are reversible. That is, the high entropy state after the block hit the stack, if you reverse the momentum of all bodies, will eventually evolve to the low-entropy state consisting of the stack and the block - which would look very improbable (like an egg unbreaking), but possible, nevertheless.

    But, because of numerical approximation in computer code, if you actually try to do it (reverse the momentum), you'll notice the simulation won't quite go back to the state it was before.

    So, here's a challenge for you: can you come up with a simulation that is deterministically reversible?

  • app4soft 6 years ago

    Nice.

    FTR, Also Pyslvs-UI may be useful for 2D kinematics analyze and you also could use its core ("pyslvs"; and based on SolveSpace[2] solver) module written in Python.

    [0] https://github.com/KmolYuan/Pyslvs-UI

    [1] https://github.com/KmolYuan/pyslvs

    [2] https://github.com/solvespace/solvespace

gmurphy 6 years ago

This is great! One very naive (I'm trying to learn) question:

You have a fixed timestep for good reason, which works great if you're displaying by doing interpolation (your display frames lag the physics and are 'catching up' to them), but in some cases where you want low latency in response to player input you might want extrapolation (your display frames are ahead of the physics engine).

I believe people typically do extrapolation by projecting forward any motion in a linear fashion, but it seems this would result in occasional weirdness like geometry intersection. One solution might be to run the physics engine at a fixed timestep for the 'real' changes, but let the graphics engine use the physics engine at a non-fixed timestep to do the extrapolation, where the results of that simulation are not taken into account for the fixed timestep frames.

Is that possible in Dyna-Kinematics, and/or am I talking nonsense? :)

waltbosz 6 years ago

Did anyone else spend hours of their childhood playing The Incredible Machine ? Anytime I read about a 2D physics simulator, I can't help but think of that game.

bsenftner 6 years ago

Does the Visual Studio project require QT be pre-installed? I don't see libs or headers in the dependencies, and I don't have QT on my dev system. So the project does not compile.

prox 6 years ago

Fun and informative, a great combination!

chrisbennet 6 years ago

This is really awesome!

Karmic_Clash 6 years ago

Looks very cool!

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection