pymunk | use pythonic 2d physics library that can be | Animation library

 by   viblo Python Version: 6.4.0 License: MIT

kandi X-RAY | pymunk Summary

kandi X-RAY | pymunk Summary

pymunk is a Python library typically used in User Interface, Animation, Pygame applications. pymunk has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can download it from GitHub.

Pymunk is a easy-to-use pythonic 2d physics library that can be used whenever you need 2d rigid body physics from Python

            kandi-support Support

              pymunk has a highly active ecosystem.
              It has 783 star(s) with 181 fork(s). There are 23 watchers for this library.
              It had no major release in the last 12 months.
              There are 12 open issues and 191 have been closed. On average issues are closed in 256 days. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of pymunk is 6.4.0

            kandi-Quality Quality

              pymunk has 0 bugs and 0 code smells.

            kandi-Security Security

              pymunk has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              pymunk code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              pymunk is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              pymunk releases are available to install and integrate.
              Build file is available. You can build the component from source.
              pymunk saves you 6125 person hours of effort in developing the same functionality from scratch.
              It has 13077 lines of code, 952 functions and 112 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed pymunk and discovered the below as its top functions. This is intended to give you an instant insight into pymunk implemented functionality, and help decide if they suit your requirements.
            • Fill a space
            • Adds objects to the constraints
            • Sleep the body
            • Add a body to the space
            • Draws a wheel
            • Return the vertices of the polygon
            • Generates an ellipse from a circle
            • Generate a list of points from a polygon
            • Creates a bar chart
            • Perform a segment query
            • Generate a convex hull of a list of points
            • Query the coordinates of a point in the space
            • Step a space
            • Perform a point query
            • Creates a polyline set of points
            • Creates a polyline set for a given point
            • Updates the event loop
            • Draw a polygon
            • Setup the player level
            • Create a collision handler
            • Creates a collision handler
            • Apply a function to each arbiter
            • Parse examples
            • Draw a circle
            • Draw the frame
            • Generate geometry for a surface
            • Get the vertices of the current mesh
            Get all kandi verified functions for this library.

            pymunk Key Features

            No Key Features are available at this moment for pymunk.

            pymunk Examples and Code Snippets

            No Code Snippets are available at this moment for pymunk.

            Community Discussions


            The particle is not moving so what is the problem?
            Asked 2022-Jan-18 at 01:42

            I follow a youtube video '' and in the video he make a class that represent a ball and he used pymunk to make a body and added it to the space and after that he created a method inside the ball class that will use pygame to draw the ball and I did almost like him



            Answered 2022-Jan-18 at 01:28

            You error is both a typo and using the wrong variable.

            Inside your particles draw function...



            How many steps per update in pymunk and pyglet/pygame?
            Asked 2021-Dec-30 at 19:52

            I have read that advancing the pymunk space by several steps per screen update can lead to a smoother simulation and help prevent objects tunneling through each other, e.g. How to prevent fast moving objects passing through statics when calculating pi with colliding blocks. The example suggests this:



            Answered 2021-Dec-30 at 19:52

            The big downside is performance. It is much more expensive to call step 10000 times than 1 time for a given period of time.

            I imagine that sooner or later there will be other effects as well, for example around the floating point precision when the dt becomes very small. E.g if an object has a very low velocity it will move a tiny distance, and if that number is very small it might not be possible to accurately store it as a floating point number (64 bit double in the case of pymunk), so that errors accumulate and the end result is a worse simulation than calling step only once.



            Clarification of collisions in pymunk
            Asked 2021-Dec-05 at 19:42

            I've been investigating Pymunk as a possible platform for a spatial chemistry simulation. I naively thought that when two shapes collide there would be a single contact point. In fact that can be up to two contact points. I also find that each contact point has two points, point_a and point_b. The documentation says

            point_a and point_b are the contact position on the surface of each shape

            I wonder if someone less naive than I am could explain:

            • Why can the ContactPointSet contain one or two contact points only and not three or more?
            • Why are point_a and point_b for a given ContactPoint not necessarily the same point, since they are the point at which contact occurs between two shapes?
            • Is the shape that point_a is on guaranteed to be arbiter.shapes[0] and the shape that point_b is on guaranteed to be arbiter.shapes[1], or do I need to check that?




            Answered 2021-Dec-05 at 19:42

            Im dont know enough of the collision algo to answer from the mathematical background, but I can give some help on the way:

            1. This is from the collision algorithm used. For easy (e.g. Circle to circle) collisions only one point is found, as you can see here: In more advanced cases, e.g. Poly to Poly, then the GJK & EPA algorithms are used, and this can produce one or two points.

            2. I think the reasoning is shown in the below picture. The points are located on each shape, and since they can be overlapping it becomes natural with one for each.

            1. I suspect so, but am not 100% sure.

            If you are intersted about the GJK & EPA implementation, there's a intro blog post from when it was first introduced into Chipmunk here:



            AssertionError: The shape's body must be added to the space before (or at the same time) as the shape
            Asked 2021-Nov-07 at 08:15

            I am trying to make a game, which includes polygons in pymunk, and to be able to do that in pymunk I decided to use many segments and draw it as a solid polygon. When I implement the code im getting an error

            My code



            Answered 2021-Nov-07 at 08:15

            StaticPoly.bodies contains pymunk.Bodys. These bodies must also be added to the space.

            Reed the error message:

            The shape's body must be added to the space before (or at the same time) as the shape.

            Either before



            Pymunk bodies colliding without touching each other
            Asked 2021-Nov-02 at 21:17

            Why do bodies in pymunk keep colliding without actually touching each other even after the position and body shape is correctly set?

            You will see from my code below that the bird keeps colliding with the ball without actually touching the ball.



            Answered 2021-Nov-02 at 21:16

            The 2nd argument of pymunk.Circle is the radius, but not the diameter:

            shape = pymunk.Circle(body, 60)



            How to make a Static Rectangle shape in pymunk?
            Asked 2021-Sep-07 at 13:36

            My question is pretty straightforward I just wanna know a way to make a static body, which is a rectangle using pymunk. I tried reading the docs and found out about Segments, but couldn't really understand it. So any kind of help is very much appriciated !



            Answered 2021-Sep-07 at 08:54

            Either you can use the static body already attached to the Space, or you make a new one. To create a rectangle, either you provide the corners to the Poly constructor (as shown below), or you use the shorthand Poly.create_box method.



            How to make a L-shaped body in pymunk?
            Asked 2021-Aug-23 at 19:22

            I am new to pymunk and I want to make a L-shaped body like this.

            I read that it is possible to have two shapes attached to same body but the best I got is this.

            The code I used is this:



            Answered 2021-Aug-23 at 19:22

            The problem is that both Poly shapes that are created with the shorthand create_box method are created with their center at the position of the body they are attached to. So the two boxes are positioned on top of each other.

            To fix this you need to use the more generic Poly constructor. In this way you can pick the positions as you want.

            If I just take your picture and write up the coordinates times 10, it would be something like this:



            A few questions about pymunk's accuracy
            Asked 2021-Aug-11 at 06:29

            I am interested in simulating a sort of rod-pendulum system:



            Answered 2021-Aug-11 at 06:29
            1. The torque is reset every step, as written here: Given this I think the expectation is that it should slow down over time. I should also add that usually its a bit tricky to set these kinds of values manually, better would be to use a SimpleMotor constraint.

            2. Yes, the center of gravity seems to be the issue here just as you write. The center of gravity will be at 0,0 of the Segment (and similar at 0,0 in case you create a Poly shape). So c1 has the center of gravity in the middle, while c2 has it at one end. You can either just change the definition of c2 to be (b2, (0,-20), (0,20)...) and modify the position of the body to compensate, or use the body center_of_gravity property to adjust its location.

            3. I think the issue is that the moment you use for the two segment bodies are very extreme. The moment can be calculated with the built in method moment_for_segment, e.g.: pymunk.moment_for_segment(1000, (0, -40), (0, 40), 6) The calculated moment is 717000, which is quite different from the value in your code. You can also let Pymunk calculate the mass and moment for a body from the Shapes attached,

            4. Pymunk uses the C library Chipmunk for the actual simulations. The focus of this library was mainly gaming or other realtime uses, and the same for Pymunk. However, I know that Pymunk has been used for many different purposes, as shown in the list of uses here: page. If the algorithms inside Pymunk are accurate and comprehensive enough for your use case I do not know.

            5. Not sure.

            A final note is that its probably a good idea to use as small dt in the space.step function as possible since that will produce better simulations.



            pygame wont draw my circle in my pymunk simulation
            Asked 2021-May-26 at 09:25

            I'm fairly new to pymunk and I wanted to make physics engine for my future games, there's just a small problem, My code won't draw the circle that pygame is trying to visualize. Here's my code.



            Answered 2021-May-26 at 09:25

            You have to draw the objects before updating the display



            Pygame and Pymunk Programm loads a bit with back screen and then closes
            Asked 2021-May-24 at 09:36

            I was following this tutorial because I wanted to learn pymunk, but then the problem that is described in the title occured. I´ve already tried restarting IDLE and searching for a solution online, but its difficult to find something because I´m not getting an error message . Can you tell were the mistake is?



            Answered 2021-May-24 at 09:36

            I am getting an error message:


            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install pymunk

            You can download it from GitHub.
            You can use pymunk like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.


            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • HTTPS


          • CLI

            gh repo clone viblo/pymunk

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link