{"id":20449668,"url":"https://github.com/emmanuelmess/interactive-dynamics-physics-simulations","last_synced_at":"2026-01-23T10:17:26.984Z","repository":{"id":208331917,"uuid":"721354253","full_name":"EmmanuelMess/Interactive-Dynamics-Physics-Simulations","owner":"EmmanuelMess","description":"This is a test made for the Constraint Based Simulator. It provides a constraint satisfaction physics simulator with automatic differentiation.","archived":false,"fork":false,"pushed_at":"2024-08-17T16:57:56.000Z","size":4281,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T07:09:03.696Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":false,"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/EmmanuelMess.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":"2023-11-20T22:14:58.000Z","updated_at":"2024-10-30T06:23:52.000Z","dependencies_parsed_at":"2024-04-05T13:45:59.092Z","dependency_job_id":"43e34b9b-3f18-4fe8-827a-6b5f0d5cf488","html_url":"https://github.com/EmmanuelMess/Interactive-Dynamics-Physics-Simulations","commit_stats":null,"previous_names":["emmanuelmess/interactive-dynamics-physics-simulations"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/EmmanuelMess/Interactive-Dynamics-Physics-Simulations","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmmanuelMess%2FInteractive-Dynamics-Physics-Simulations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmmanuelMess%2FInteractive-Dynamics-Physics-Simulations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmmanuelMess%2FInteractive-Dynamics-Physics-Simulations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmmanuelMess%2FInteractive-Dynamics-Physics-Simulations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EmmanuelMess","download_url":"https://codeload.github.com/EmmanuelMess/Interactive-Dynamics-Physics-Simulations/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmmanuelMess%2FInteractive-Dynamics-Physics-Simulations/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28687438,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T05:48:07.525Z","status":"ssl_error","status_checked_at":"2026-01-23T05:48:07.129Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-15T10:43:32.203Z","updated_at":"2026-01-23T10:17:26.964Z","avatar_url":"https://github.com/EmmanuelMess.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"#  Interactive Dynamics for Physics Simulations\n\nThis is a test made for the [Constraint Based Simulator](https://github.com/EmmanuelMess/ConstraintBasedSimulator). It provides a constraint satisfaction physics simulator with automatic differentiation.\n\n## Screenshots\n\n\u003cimg src=\"./screenshots/1.gif\"/\u003e \u003cimg src=\"./screenshots/2.gif\"/\u003e\n\n\u003cimg src=\"./screenshots/3.gif\"/\u003e\n\n## Usage\n\n### Setup\n```bash\ncd code\npython3 -m venv venv\nsource venv/bin/activate\npython3 -m pip install -r requirements.txt\n```\n\n### Running\n```bash\ncd code\npython3 main.py\n```\n\n## Adding functionality\n\nGenerate a new `Constraint` subclass and use it in a case.\n\n## Design\n\n\u003cimg src=\"./design/class-diagram.png\"/\u003e\n\n## Math for a single particle\n\nThis explanation is meant to complement the references, please read that first. This explains\nhow to compute the derivates with respect to time and position.\n\n$C_p(t)$ is a constraint function on a set of particles $p$ so that:\n\n$$ \\exists t / C_p(t) = 0 \\land \\exists \\dot{C_p} $$\n\nTo obtain the constraint as a function of particles positions (instead of time) we use:\n\n$$ \\widetilde{C}_p(x(t)) = C_p(t) $$\n\nWe don't have the single particle $x(t)$ function analitically, but we can use an approximation (a Taylor approximation at $t = 0$):\n\n$$ \\widetilde{C}_p(\\widetilde{x}(t)) \\approx C_p(t) $$\n\n$$ \\widetilde{x}(t) = x + t * v + \\frac{1}{2} * t^2 * a \\approx x(t) $$\n\n$$ \\widetilde{x}(0) = x_t \\land \\dot{\\widetilde{x}}(0) = v_t \\land \\ddot{\\widetilde{x}}(0) = a_t $$\n\nAnd that lets us compute the derivatives ($p_i \\in p$ and $C^i$ is a constraint):\n\n$$ C = \\begin{bmatrix} C^0(0) \u0026 \\cdots \u0026 C^m(0) \\end{bmatrix}^T $$\n\n$$ \\dot{C} = \\begin{bmatrix} \n \\frac{\\partial C^0} {\\partial t}(0) \u0026 \\cdots \u0026 \\frac{\\partial C^m} {\\partial t}(0)\n\\end{bmatrix}^T\n$$\n\n$$\nJ = \\begin{bmatrix}\n  \\frac{\\partial C_ {p_0}^0}{\\partial x_1}(0) \u0026 \\frac{\\partial C_ {p_0}^0}{\\partial x_2}(0) \u0026 \\cdots \u0026 \\frac{\\partial C_ {p_n}^0}{\\partial x_1}(0) \u0026 \\frac{\\partial C_ {p_n}^0}{\\partial x_2}(0)  \\\\\n  \\vdots \u0026 \u0026 \\vdots \u0026 \u0026 \\vdots \\\\\n  \\frac{\\partial C_ {p_0}^m}{\\partial x_1}(0) \u0026 \\frac{\\partial C_ {p_0}^m}{\\partial x_2}(0) \u0026 \\cdots \u0026 \\frac{\\partial C_ {p_n}^m}{\\partial x_1}(0) \u0026 \\frac{\\partial C_ {p_n}^m}{\\partial x_2}(0)  \\\\\n\\end{bmatrix}\n$$\n\n$$\n\\dot{J} = \\begin{bmatrix}\n  \\frac{\\partial \\dot{C}_ {p_0}^0}{\\partial x_1}(0) \u0026 \\frac{\\partial \\dot{C}_ {p_0}^0}{\\partial x_2}(0) \u0026 \\cdots \u0026 \\frac{\\partial \\dot{C}_ {p_n}^0}{\\partial x_1}(0) \u0026 \\frac{\\partial \\dot{C}_ {p_n}^0}{\\partial x_2}(0)  \\\\\n  \\vdots \u0026 \u0026 \\vdots \u0026 \u0026 \\vdots \\\\\n  \\frac{\\partial \\dot{C}_ {p_0}^m}{\\partial x_1}(0) \u0026 \\frac{\\partial \\dot{C}_ {p_0}^m}{\\partial x_2}(0) \u0026 \\cdots \u0026 \\frac{\\partial \\dot{C}_ {p_n}^m}{\\partial x_1}(0) \u0026 \\frac{\\partial \\dot{C}_ {p_n}^m}{\\partial x_2}(0)  \\\\\n\\end{bmatrix}\n$$\n\nWe can use the result:\n\n$$\n\\ddot{C} = (J W J^T) {\\lambda}^T + \\dot{J} \\dot{\\widetilde{x}} + J W \\ddot{\\widetilde{x}} = - k_s C - k_d \\dot{C}\n$$\n\nAnd compute λ such that:\n\n$$\n (J W J^T) {\\lambda}^T + \\dot{J} \\dot{\\widetilde{x}} + J W \\ddot{\\widetilde{x}} + k_s C + k_d \\dot{C} = 0\n$$\n\nWe compute using an approximate least squares method.\n\n## Thanks\n* [Interactive Dynamics](https://dl.acm.org/doi/pdf/10.1145/91394.91400) by Andrew Witkin, Michael Gleicher and William Welch\n* [An Introduction to Physically Based Modeling: Constrained Dynamics](https://www.cs.cmu.edu/~baraff/pbm/constraints.pdf) by Andrew Witkin\n* [Constrained dynamics](https://sites.cc.gatech.edu/classes/AY2017/cs7496_fall/slides/ConstrDyn.pdf) by Karen Liu\n* [JAX](https://jax.readthedocs.io/en/latest/notebooks/quickstart.html) by The JAX Authors\n* [pygame](https://www.pygame.org) by the pygame community\n\n## License\n\n```text\nMIT License\n\nCopyright (c) 2023 EmmanuelMess\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmanuelmess%2Finteractive-dynamics-physics-simulations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femmanuelmess%2Finteractive-dynamics-physics-simulations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmanuelmess%2Finteractive-dynamics-physics-simulations/lists"}