Hello all!
I’m trying to write a script for to construct the golden ratio rectangle such that I can control the iterations/ growth of the rectangle through a slider. Can someone nudge me in the right direction?
I’ve tried different approaches with no success. PFA file for reference. golden spiral.gh (20.5 KB)
Skipped a step or two on geometric construction, added some programming gimmicks. Had interesting mistakes along the way, but didn’t keep screen images.
I wasn’t able to recreate the best mistakes that I saw earlier by accident. Random “spirals” of rectangles, cool stuff. But this adds a few deliberate goofs (blue group) that make interesting patterns of overlapping, scaled rectangles. Zoom in/out
However, I checked these out previously. I was looking for a more logic-based script, if possible, without using anemone or other direct plugins like Fibonacci spiral.
If anybody has some solution like that, it would be great.
import Rhino
import math
#defaults for variables
if not scale:
scale=1
if not x: #number of values in fibonacci sequence
x=10
# generate fibonacci sequence
fs={0:0,1:1}
a=[0,0,1] #need extra 0 here for circle centres
def fi():
for i in range(x):
if not i in fs:
fs[i]=fs[i-1] + fs[i-2]
a.append(fs[i])
fi()
#scale the sequence
if scale != 1:
for i in range (len(a)):
a[i]*=scale
r=[] #container for radii
r=a[2:] #trim the 0's from a because we can't have 0 radius to start with
normal = Rhino.Geometry.Vector3d.ZAxis
angle = math.pi/2
i=0
accvec=Rhino.Geometry.Vector3d(0,0,0) #mass addition container for vec
################################
# generate arcs and rectangles #
################################
b=[]#container for the arcs
f=[]#container for rectangles
for n in r:
vec = Rhino.Geometry.Vector3d(0, -a[i],0)
vec.Rotate(-angle*i, normal)
accvec += vec #mass addtion of vec, so that each arc gets its own + previous transforms
radius=n # equal to the fibonacci number
plane=Rhino.Geometry.Point3d(accvec)#set center point for the arc
arc=Rhino.Geometry.Arc(plane, radius, angle)
arc.StartAngle = -angle*i #change arc start and end angle so each starts -90 degrees more turned
arc.EndAngle = arc.StartAngle + angle # a 90 degree arc
b.append(arc)
# make the rectangle around the arc:
plane = Rhino.Geometry.Plane.WorldXY
corner1=arc.StartPoint
corner2=arc.EndPoint
rectangle = Rhino.Geometry.Rectangle3d(plane, corner1, corner2)
f.append(rectangle)
i+=1
##################
# generate cubes #
##################
g=[]#container for the cubes
j=0
for rectangle in f:
profile = Rhino.Geometry.Rectangle3d.ToNurbsCurve(rectangle)
cube = Rhino.Geometry.Extrusion.Create(profile, r[j], True)
j+=1
g.append(cube)
Let’s say E(x) is the edge length of the square at iteration “x”, and L is the initial base length of the square edge on which the whole drawing is based, the general edge length formula is something like: E(x) = L times ϕ at the power of x
iteration 0 you get E(0) = L * ϕ ^ 0 = L (starting square with edge L)
iteration 1 you get E(1) = L * ϕ ^ 1 = L * ϕ
…
iteration 55 you get E(55) = L * ϕ ^ 55
then, for simplicity, assuming we start drawing this thing from iteration 1 instead of iteration 0, it might look like the following:
we have a start point and a reference plane
draw a square along the reference plane with edge length E(1) = L * ϕ
How could you check these out when I just wrote them? I don’t know what “more logic-based” means? You could ask for more clear logic, a simpler Anemone loop, and I would be interested.
Your solution that doesn’t require a loop has been simmering in the back of my mind. Fascinating, though I don’t understand all the details despite studying the code and re-reading your detailed explanation. Brilliant insight
In the process, I found a way to generate that spiral of rectangles I mentioned. Connect the ‘Start’ slider to the ‘Step’ (N) input of Series and use values greater than one:
it’s not coded using a loop component, but also mine is a loop in the end
I say so because at a certain point it uses the Partial results of a Mass Addition component, which means that it requires the calculation of all previous steps up to the Nth -1 step, to generate the Nth solution
a solution that wouldn’t require a loop should allow to determine position of square at iteration -for instance- number 137 without calculating all the previous ones: despite being able to calculate the edge length of square at that iteration independently from any previous one, I’m not able to think a way to know where that square is located without calculating all the previous ones first