Circle Packing Demo
Simple demo to show off a simple circle packing algorithm. Only shows groups of three because I didn't want to put the time in to dynamically detect which circles were touching out of a pile of circles. The only input is clicking with the mouse, and mouse position.
The gist:
You place a circle of some radius r1 down on the field. When you place a second circle down with radius r2, its center must be a distance r1+r2 away from the first circle's center in order to be barely touching. We can visualize all the possible positions circle2 could go as a ring around circle1 that has a radius of r1+r2.
When you place a third circle down with radius r3, it must simultaneously be r1+r3 away from circle1 and r2+r3 away from circle2 in order to be just touching both. When can visualize the possible positions where this occurs as being the intersections between the "possibility rings" around circle1 and circle2.
There are lots of ways to calculate the intersecting points between two circles. For this project, I used this easy-to-translate-to-code solution derived by Salix Alba on Stackexchange: https://math.stackexchange.com/a/1033561
This algorithm can place a third circle between any two circles that you know are touching.
Made with raylib, you can view the source code here (1 file): https://github.com/Cosmonaut800/Circle-Packing-Demo
Status | Released |
Category | Other |
Platforms | HTML5 |
Author | Cosmonaut800 |
Leave a comment
Log in with itch.io to leave a comment.