{"id":20067588,"url":"https://github.com/gnrlleclerc/soft-bodies-simulator","last_synced_at":"2026-06-04T22:31:42.635Z","repository":{"id":178423045,"uuid":"388950452","full_name":"GnRlLeclerc/Soft-Bodies-Simulator","owner":"GnRlLeclerc","description":"Soft Body Simulation using python with numpy and pygame modules","archived":false,"fork":false,"pushed_at":"2024-01-08T14:32:37.000Z","size":112,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-12T23:27:30.645Z","etag":null,"topics":["physics","python","real-time","simulation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GnRlLeclerc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-23T23:24:07.000Z","updated_at":"2022-06-20T00:50:19.000Z","dependencies_parsed_at":"2024-01-08T15:58:51.724Z","dependency_job_id":null,"html_url":"https://github.com/GnRlLeclerc/Soft-Bodies-Simulator","commit_stats":null,"previous_names":["tibox2021/soft-bodies-simulator","gnrlleclerc/soft-bodies-simulator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GnRlLeclerc%2FSoft-Bodies-Simulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GnRlLeclerc%2FSoft-Bodies-Simulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GnRlLeclerc%2FSoft-Bodies-Simulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GnRlLeclerc%2FSoft-Bodies-Simulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GnRlLeclerc","download_url":"https://codeload.github.com/GnRlLeclerc/Soft-Bodies-Simulator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241494180,"owners_count":19971871,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["physics","python","real-time","simulation"],"created_at":"2024-11-13T14:02:15.997Z","updated_at":"2026-06-04T22:31:42.629Z","avatar_url":"https://github.com/GnRlLeclerc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Soft-Bodies-Simulator\n2D soft boy simulation using pygame, numpy\n\n---SETUP---\nMade in python 3.7.3 64-bit\nModules used : pygame, numpy, and built-in modules\n\n---GUIDE---\nThe code is documented\n\nExample setups are provided in main.py\n\nInteracting with the simulation :\n\n-\u003e right-click to pick up the closest point to the cursor and move a shape\n\n-\u003e keys (AZERTY)\n- A : show normal vectors (only recommended for SoftBall objects, not well implemented for Springy Boxes and Structures)\n- Z : show springs (in red)\n- E : show max FPS available. Based on each frames' computing time, displays the maximum fps available. Refreshes every second\nIf the specified fps is too high, the simulation will run slower, but at the specified time step (1/fps) for Euler integration.\nBetter fps improves stability and enables higher force coefficients with lighter masses (else, unstable oscillations can occur)\n\n---PHYSICS---\n\nThe different objects are generated inside a box the size of the window.\n\nELements of an object :\n- points with the same mass : the sum of the masses of an object's points is the object's mass\n- springs that link different points. (for soft objects)\n- internal pressure force, that simulates an object's elasticity in a way that cannot be reproduced with springs\n\nForces applied to points and Euler integration\n\n- Springs : 3 parameters : l0, k, kd\nl0 : rest length of the spring\nk : stiffness coefficient of the srping\nkd : dampening coefficient, in order to avoid infinite oscillations\n\nF = k * (length - l0)  # spring elastic force : Hooke's law\nFk = kd * d(length)/dt = kd * spring_points_relative_speed  # dampening force\n\n- Pressure (not yet finished)\nAn object can be subject to a pressure force :\nP = pressure_coeff * (1/current_surface - 1/rest_surface)\n\npressure_coeff : P = nRT/V =\u003e pressure_coeff = total energy of the gaz particle model.\nWhen pressure_coeff is increased, the particle's energy is increased with the external pressure (total energy/rest volume). The result is a less compressible particle\n\npressure dampening coefficient : in order to dissipate energy, a dampening force proportionnal to each point's relative velocity to the barycentre is applied. It is linked to the particle's internal viscosity\n\nF/S = visc * dv/dx\nF = visc * dv.dx * S = visc * rel_velocity * S/dx\n=\u003e pressure_dampening_coeff = viscosity * distance_between_barycentre_and_point = viscosity * radius\n\nIn reality, pressures are scalar fields in volume that apply forces to surfaces\nIn this 2D engine, pressures are scalar fields in shape surfaces that apply forces to the lines that make up the outline of a shape.\n\nPressure model : in a perfect gas : P*V = n*R*T, so P = constant / V\nHence why in this model, pressure is proportional to 1/V, or 1/surface in 2D.\n\nthe object_stiffness coefficient describes the compressibility of the object.\n\nA pressure force is applied to each pair of point that are part of an object's outline, in the direction normal to the outline. The pressure force is shared by both points, who are both affected by half the force.\n\nA pressure damping force also needs to be applied to reduce oscillations between opposing points that are not\nlinked by any spring. This force works like a spring damping force between every point and the shape's barycentre.\n\nAll of theses forces, along with gravity, are integrated in real time using Euler integration.\n\nRemarks :\n- the engine can be unstable if the coefficients entered are too great : because of numeric integration with a finite time step, stiffness and dampening coefficients that are too high create unstable oscillations and abrupt changes in position. They must be avoided for the engine to work correctly. The main.py file provides a working example with reasonable coefficients.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgnrlleclerc%2Fsoft-bodies-simulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgnrlleclerc%2Fsoft-bodies-simulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgnrlleclerc%2Fsoft-bodies-simulator/lists"}