Matheart / manim-physics

Physics simulation plugin of Manim that can generate scenes in various branches of Physics.
317 stars 28 forks source link

I want to animate a rope/string. What's the best approach for this? #7

Open kevinlu1248 opened 3 years ago

kevinlu1248 commented 3 years ago

Exactly as stated in the title. I'm thinking about making it like a chain, using some constraints, but add smaller and more segments. Is this a viable approach? Thank you for all your work thus far.

pdcxs commented 3 years ago

It is not an easy task to create a rope in all physics engines. To the best of my knowledge, the only way to simulate rope is using joint segments/springs. The following links may be helpful: Stackoverflow: How to create rope pymunk joint document

kevinlu1248 commented 3 years ago

As an update on this, I actually do have something functioning, although it does have quite a bit of overhead and it has some strange rippling effects. Further, it can move through objects when moving too fast. I will send a video later showing this.

kevinlu1248 commented 3 years ago

Brief example of a point trying to run away while leashed to two nails.

https://user-images.githubusercontent.com/26889185/127433434-c9df13a8-df8a-4b59-88b8-31c61fb26c57.mp4

kevinlu1248 commented 3 years ago

It's basically a chain:

https://user-images.githubusercontent.com/26889185/127433690-3c51daad-f2f5-4c79-ade7-8543e2982669.mp4

But then every frame I get a spline interpolator to smoothen the curve:

https://user-images.githubusercontent.com/26889185/127433749-a1839f42-4647-4afd-a3bf-01bf6f3a1f2c.mp4

At the moment, I'm facing a few issues with this implementation:

On the other hand this method does produce a decent rope without too many chains at a reasonable level of performance. I can do a PR if your interested in having this in your library.