Circle Packing
Aug 20, 2008 / Comments (0)I’ve been working yesterday in a Circle Packing, and I started with matsys pseudo-code. I found a lot bugs, finally I decided to make a mixture between his algorithm and mine. Circle Packing can be a very usefull algorithm and I think until now we have not seen their real power applied to architecture.
This is my little contribuition (pseudo_Code)
1_ Input: maxradius, boundary, iterations (not necessary the number of circles)
2_Add in a random position within the boundary a circle with maximum radius
3_Add a Random Point
4_If this Point is inside of the Circle just created, add another one and delete the old one
5_Add Line to this point (out of the circle) to the center of the circle, (here I use the same idea of matsys) “If the distance is greated than the maximum radius add a circle at that point with the maximum radius. If the distance is less than the maximum radius, add a circle at that point with the measured distance.”
6_ add another point and test if this point is within of any circle and add a line to every center circle to find the closest circle (step _5)
7_ repeat the steps 5 to 6 the number of the iterations
soon more images.
share, modify and send me an Image
best
Option Explicit
‘Script written by <Carlos de la Barrera>
‘Script copyrighted by <Carlos de la Barrera>
Call Main()
Sub Main()
Dim Pt, R
Pt = Array(rnd * 100, rnd * 100, 0)
R = FuncCir(Pt, 10)
Call Pack(R)
End Sub
Function Pack(R)
Dim Pt, i, count
count = Rhino.GetInteger(” number of circles “, 50, 2, 1000)
If IsNull (count) Then Exit Function
Dim ArrData()
For i = 0 To count
ReDim Preserve ArrData(i)
ArrData(i) = R
Pt = Array(Rnd * 100, rnd * 100, 0)
Dim j
Dim t: t = 0
For j = 0 To UBound(ArrData)
If Rhino.IsPointOnSurface(ArrData(j)(1)(0), Pt)Then
Call Rhino.print (”point in surface”)
t = t + 1
End If
Next
If (t = 0) Then
ReDim ArrLine(UBound(ArrData))
Dim k, line
For K = 0 To UBound(ArrData)
line = Rhino.AddLine(Pt, Rhino.CircleCenterPoint(ArrData(k)(0)))
ArrLine(k) = Line
Next
Dim d, d2, l
d = funcDist(Pt, ArrData(0)(0), ArrLine(0))
For l = 0 To UBound(ArrLine)
d2 = funcDist(Pt, ArrData(l)(0), ArrLine(l))
If d < d2 Then
‘Call Rhino.Print (”nothing”)
Else
d = d2
End If
Next
R = FuncCir(Pt, d)
Call Rhino.DeleteObjects (ArrLine)
End If
Next
End Function
Function FuncCir(p, D)
If D >= 10 Then
D = 10
End If
Dim plane
Dim R(1)
plane = Rhino.PlaneFromFrame(p, Array(1.0,0.0,0.0), Array(0.0,1.0,0.0))
R(0) = Rhino.AddCircle(plane, D)
R(1) = Rhino.AddPlanarSrf(Array(R(0)))
FuncCir = R
End Function
Function funcDist(Pt, circleP, Line)
Dim Ap, j, d
Ap = Rhino.CurveCurveIntersection (circleP, Line)
For j = 0 To UBound(Ap)
d = Rhino.Distance(Pt, Ap(j, 1))
Next
funcDist = d
End Function
the other day I listen: - talk it’s easy, ¡ show me the code ! -
























