Circle and Sphere Packing
I’ve yet to figure out how to go about turning my main Charge field atomic modeling project into a molecule maker, then into an Addon.
In the meantime, here’s some proof of life, a quick and easy Blender project, with AI help of course. Circle and sphere Packing. Still, it took me a few hours to request and understand it, make notes and changes, then find and correct a bad initial y_offset value suggested in the sphere packing section.
1. A 2d hexagonal close packed array of overlapping circles, 7 circles;
2. A grid of circles with variable rows and columns;
3. 3d hexagonal close packed spheres consisting of two alternating layers.
First un-comment (remove) the pair of triple ( ''' ) quotes at the top and bottom of the section you wish to mess with.
Here’s the AI instructions for creating the Blender python SG grid.
AI wrote.
QUOTE
How to use the script
Open the Scripting Workspace: Open Blender and switch to the Scripting workspace via the tabs at the top.
Create a New Script: In the text editor window, click the New button.
Paste the Code: Copy the code above and paste it into the editor.
Adjust Settings (Optional): Change the variables at the top of the script (circles_across, rows_down, circle_radius, overlap_factor) to get your desired grid.
Run the Script: Click the Run Script button (the "play" icon) in the text editor header.
How it works
Variable Control: The top section provides a clear way to control the grid's dimensions and overlap.
Clear Scene: The script first deletes any old circles from previous runs to ensure a clean slate. This is a best practice for re-running scripts.
Hexagonal Spacing: The core of the hexagonal grid is in the x_spacing and y_spacing calculations. A hexagon's geometry dictates that the vertical distance between row centers is a multiple of $\sqrt{3}/2$.
Row Offset: A hexagonal pattern requires every other row to be horizontally shifted. The if row % 2 == 1: statement handles this by adding x_offset to odd-numbered rows.
Overlap Control: The overlap_factor variable determines the distance between circle centers.
1.0 makes adjacent circles touch perfectly.
A value greater than 1.0 (e.g., 1.2) decreases the center-to-center distance, causing the circles to overlap.
A value less than 1.0 (e.g., 0.8) increases the distance, creating gaps between the circles.
UNQUOTE
Please take it or leave it as is. Brief circle and sphere packing scripts.
4
2 comments
Robert McBride
4
Circle and Sphere Packing
CG Python Academy (Free)
skool.com/cgpython
3D artists learning Blender Python.
Leaderboard (30-day)
Powered by