{"id":18889141,"url":"https://github.com/alejo1630/colliding_blocks","last_synced_at":"2025-09-14T18:41:10.385Z","repository":{"id":175399359,"uuid":"591094525","full_name":"alejo1630/colliding_blocks","owner":"alejo1630","description":"This Python code computes the kinematics data (linear momentum and kinetic energy) for the 2D collission between 2 blocks and a rigid wall taking into account the coefficient of restitution but ignoring the friction.","archived":false,"fork":false,"pushed_at":"2023-01-20T00:05:42.000Z","size":109,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-31T13:08:54.814Z","etag":null,"topics":["colliding-blocks","collision","compute-pi","python","vpython"],"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/alejo1630.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,"zenodo":null}},"created_at":"2023-01-19T22:50:41.000Z","updated_at":"2023-01-20T00:09:36.000Z","dependencies_parsed_at":"2023-07-15T10:16:44.944Z","dependency_job_id":null,"html_url":"https://github.com/alejo1630/colliding_blocks","commit_stats":null,"previous_names":["alejo1630/colliding_blocks"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alejo1630/colliding_blocks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejo1630%2Fcolliding_blocks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejo1630%2Fcolliding_blocks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejo1630%2Fcolliding_blocks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejo1630%2Fcolliding_blocks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alejo1630","download_url":"https://codeload.github.com/alejo1630/colliding_blocks/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejo1630%2Fcolliding_blocks/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267882830,"owners_count":24160214,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["colliding-blocks","collision","compute-pi","python","vpython"],"created_at":"2024-11-08T07:47:44.798Z","updated_at":"2025-07-30T14:33:22.503Z","avatar_url":"https://github.com/alejo1630.png","language":"Python","readme":"# Colliding Blocks\n\nThis Python code computes the kinematics data (linear momentum and kinetic energy) for the 2D collission between 2 blocks and a rigid wall taking into account the [coefficient of restitution](https://en.wikipedia.org/wiki/Coefficient_of_restitution) but ignoring the friction. \n\n## 🔰 How does it work?\n\n- The code uses [VPython](https://vpython.org/) library to create the 2D-3D interactive environment and the physics interactions.\n  \n\u003cimg src = \"https://github.com/alejo1630/colliding_blocks/blob/main/Image_readme/1.png\" width=\"600\"\u003e\n\n- Letter A is set for the red block and the letter B is set for the green block.\n- User has to enter the following parameters\n  - Blocks' mass.\n  - Initial velocity of the blocks (in the main case the red block doesn't have initial velocity).\n  - Coefficient of restitution between the red and the green block.\n  - Coefficient of restitution between the red block and the rigid wall.\n\n- After each collision the kinematic data is computed using the following equations (Notation: 1-Before collision, 2-After collision):\n  - Conservation of momentum:\n  $$m_A (v_A)_1 + m_B (v_B)_1  = m_A (v_A)_2 + m_B (v_B)_2$$\n  \n  - Conservation of energy:\n  $$\\frac{1}{2} m_A {(v_A)_1}^2 + \\frac{1}{2} m_B {(v_B)_1}^2  = \\frac{1}{2} m_A {(v_A)_2}^2 + \\frac{1}{2} m_B {(v_B)_2}^2 $$\n  \n  - Coefficien of restitution between blocks:\n  $$e = \\frac{(v_B)_2 - (v_A)_2}{(v_B)_1 - (v_A)_1}$$\n  \n  - Coefficient of restitution between the red block and the rigid wall:\n  $$e = -\\frac{(v_A)_2}{(v_A)_1}$$\n\n- Kinematic data for both blocks is computed for each step of time during the simulation:\n  - Linear momentum\n  \n  \u003cimg src = \"https://github.com/alejo1630/colliding_blocks/blob/main/Image_readme/2.png\" width=\"400\"\u003e\n  \n  - Kinetic energy\n  \n  \u003cimg src = \"https://github.com/alejo1630/colliding_blocks/blob/main/Image_readme/3.png\" width=\"400\"\u003e\n  \n- There is an special set of parameters which could be used to calculated the digits of Pi $(\\pi)$.\n  - All the coefficients of restitution muts be equal to 1 (perfectly elastic)\n  - Mass' A must be equal to 1.\n  - Mass' B bust be equal to $100^{n-1}$, where $n$ is the number of digits of Pi computed based on the number of collision between all the bodies during the simulation. For example:\n    - If $n = 1$ $(m_B = 1 kg)$, the number of collision would be $3$\n    \n    - If $n = 2$ $(m_B = 100 kg)$, the number of collision would be $31$\n    \n    - If $n = 3$ $(m_B = 10000 kg)$, the number of collision would be $314$\n    \n - An explanation of this peculiar phenomenon is described by [G.Galperin](https://www.maths.tcd.ie/~lebed/Galperin.%20Playing%20pool%20with%20pi.pdf) with a lot of math, but there is an incredible and illustrative explanation in the [3Blue1Browm Youtube Channel](https://www.youtube.com/watch?v=jsYwFizhncE)\n \n    \n## 🔶 What is next?\n\n- Increase the number of blocks and rigid walls. \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejo1630%2Fcolliding_blocks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falejo1630%2Fcolliding_blocks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejo1630%2Fcolliding_blocks/lists"}