Golden ratio rectangle


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)

TIA :slight_smile:

Like this?

golden_rectangle.gh (6.0 KB)

– Dale

I ran across this old code a couple of days ago. @dale derives the ratio while I just use it.


golden_rectangle_2024Aug22a.gh (4.5 KB)

1 Like

Hey!

I’m looking for this -
image

Starting with the 1 x 1 square and growing from there.

@Joseph_Oster

Hi @Ni_DAK,

Here is an old RhinoScript I wrote some years ago. Perhaps it will give you an idea how to structure your solution.

FibonacciSpiral.rvb (2.3 KB)

Just drag and drop on top of a running Rhino for Windows. Then run FibonacciSpiral.

– Dale

2 Likes

What are we supposed to do with a “.rvb” file? I reached for Anemone and Wikipedia where I read a simple description and saw this image:

Skipped a step or two on geometric construction, added some programming gimmicks. Had interesting mistakes along the way, but didn’t keep screen images.


golden_rectangle_2024Aug23a.gh (25.6 KB)

2 Likes

@Joseph_Oster,

– Dale

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 :exclamation:


golden_rectangle_2024Aug23b.gh (28.4 KB)

P.S. Another interesting “mistake”:


golden_rectangle_2024Aug23c.gh (28.2 KB)

P.P.S. Another variant with blue group “wrench” to throw in the works:


golden_rectangle_2024Aug23d.gh (31.6 KB)

2 Likes

@Joseph_Oster @dale
Thank you for these solutions. They work great.

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.

I have this fibonacci python script but I forgot where it came from.

fibonacci_02_python.gh (8.3 KB)

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)
2 Likes

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
    image
  1. draw a square along the reference plane with edge length E(1) = L * ϕ

  2. move the reference plane along a vector on that plane that has both X and Y components equal to square edge length

  3. rotate that new plane 90° counterclockwise

  • repeat steps 1, 2, 3 again on the new plane taking into account that you are at the next iteration so with a new edge length: rinse and repeat forever :slight_smile:

in GH it might look like this (be aware, this is a very dirty sketch :upside_down_face: ):

golden ratio squares.gh (17.7 KB)

note the planes progression :+1:

4 Likes

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.


golden_rectangle_2024Aug24a.gh (26.0 KB)

You can get that spiral I mentioned (not random) by setting the ‘Index’ slider (blue group) to ‘1’.


P.S. I tried adding the arc but ended up with three of them :interrobang: No idea yet why?


golden_rectangle_2024Aug24b.gh (35.8 KB)

P.P.S. I came up with a single arc line but it’s not what I wanted. :roll_eyes: Flailing…


golden_rectangle_2024Aug24c.gh (38.0 KB)

2 Likes

It’s pretty obvious that multiplying by one is pointless, eh? So this:

GR_inno1

is equivalent to this:

GR_inno2

I understand you might want to start with an initial value that is not one…

GR_inno3

Nice work to get code that doesn’t require a loop :exclamation: :+1:

2 Likes

this made me laugh hard :smiley: you are 100% right :smiley:

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 :exclamation:

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:

GR_inno4b

3 Likes

it’s not coded using a loop component, but also mine is a loop in the end :slight_smile:

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 :slight_smile:

3 Likes

Thanks a lot! This is exactly what i was looking for :heart: