Grasshopper

algorithmic modeling for Rhino

# circle packing constraints

I'm using a circle packing vb script, but i need it to do a few more things. Right now it populates a box with circles starting from the largest moving outward.  This is good, however I would like to be able to setup a min and max size of the circles. The only other thing I want to do is set the start point so I could move a point such as an attractor around to get multiple variation using the same size and number. The script is included in the grasshopper file below.

Any help would be greatly appreciated,

Views: 21451

Attachments:

### Replies to This Discussion

heres the script btw:

A = Nothing

If Not C.IsClosed Then
Print("Your input curve is not closed.")
Exit Sub
End If

'Create a new Random class in VB.NET
Dim RandomClass1 As New Random()

Dim Circle_List As New List(Of OnCircle)
Dim X, Y, Z As Double

For i As Integer = 0 To N - 1

REPEAT:
' define random x, y and z values
X = RandomClass1.NextDouble() * (U.Max - U.Min) + U.Min
Y = RandomClass1.NextDouble() * (V.Max - V.Min) + V.Min
Z = 0

' create the center point
Dim my_pt As New On3dPoint(X, Y, Z)
Dim obj_circle As OnCircle

' check if the point is inside the boundary
If Not Rhutil.RhinoPointInPlanarClosedCurve(my_pt, C) = 1 Then
GoTo Repeat
End If

' check if the point is inside an existing circle
Dim dist As Double
For Each obj_circle In Circle_List
dist = my_pt.DistanceTo(obj_circle.Center)
' find a new random point
GoTo REPEAT
End If
Next

' define the radius of the current circle such that it is tangent to its closest neighbor
' Step 1: define a radius for my_pt that is tangent to the boundary
Dim t As Double
C.GetClosestPoint(my_pt, t)
Dim point As New On3dPoint
C.EvPoint(t, point)

' Step 2: find the closest neighbor and adjust the radius if necessary
For Each obj_circle In Circle_List
End If
Next

Dim my_circle As New OnCircle(my_pt, radius)

Next

A = Circle_List
Updated your script and translated it into RhinoCommon as well.

Can you be a bit more specific about what controls you precisely want to add? Start point for the first circle only?

--
David Rutten
david@mcneel.com
Attachments:
i'm looking to set the starting point so I can better control where the circles are positioned. So if I select a starting point the circles would organize in a larger quantity near that point. I also want to be able to set the min radius and max radius for the circles for fabrication reasons.
But your circles are placed at random at the moment. You're going to have to come up with an entirely new algorithm for placing them.

--
David Rutten
david@mcneel.com

--
David Rutten
david@mcneel.com
Attachments:
thanks a lot that works great
hi, david.
I have a problem.
I wanna control radius with some tolerance.
(ex)integer 1, 2, 3, .... or 0, 0.5, 1, ...) Will you show me the solution?

jungsuk ko
5628246@naver.com
from seoul, south korea
This algorithm is a lot slower though.

--
David Rutten
david@mcneel.com
Attachments:
Archive file written with newer version: 0.8.0001

Ah, major release coming soon.
Major release coming next at any rate...

I felt the re-introduction of clusters warranted a minor version bump.

--
David Rutten
david@mcneel.com
Good spot...
You mean clusters that allow instancing and recursion... right?

is the 'silhouette from multiple rectangles' thing for visualizing them in the canvas?