How do you construct rectangular figures ("golden rectangles") using the Fibonacci numbers in Mathematica using graphics? I know that the basis of the construction of these figures are the formulae for summing the terms, the odd-indexed terms, the even-indexed terms and the sum of the squares of the terms. I'm really confused on how to obtain the rectangular figures.


NestList[] is very handy for situations like this:

tr[Polygon[p_]] := Polygon[Composition[TranslationTransform[First[p]],
   AffineTransform[{{0, -1}, {1, 0}}/GoldenRatio], TranslationTransform[-Last[p]]] @ p]

g1 = Graphics[{EdgeForm[Black], MapIndexed[{ColorData[61] @@ #2, #1} &, 
    NestList[tr, Polygon[{{GoldenRatio, 0}, {GoldenRatio, 1}, {0, 1}, {0, 0}} // N], 10]]}]


If you want to see the accompanying golden spiral as well:

tr[Circle[c_, r_, ang_]] :=
   Circle[c + r AngleVector[Last[ang]]/(1 + GoldenRatio), r/GoldenRatio, ang + π/2]

Show[g1, Graphics[{Directive[Pink, AbsoluteThickness[2]],
                   NestList[tr, Circle[{1, 1}, 1, {π, 3 π/2}], 10]}]]

golden spiral


you mean something like this?

Graphics[{Red, Rectangle[{0, 0}, {Fibonacci@6, Fibonacci@5}], Green, 
Rectangle[{0, 0}, {Fibonacci@4, Fibonacci@5}], Yellow, 
Rectangle[{0, 0}, {Fibonacci@4, Fibonacci@3}], Blue, 
Rectangle[{0, 0}, {Fibonacci@2, Fibonacci@3}], Pink, 
Rectangle[{0, 0}, {Fibonacci@2, Fibonacci@1}]}]    


but if you want the real thing, here you are..

gr[0] := {{0, 0}, {1, -1}};
gr[n_] := 
Module[{φ = GoldenRatio, m = Mod[n, 4], a, b, c, 
d}, {{a, b}, {c, d}} = gr[n - 1];
Switch[Mod[n, 4], 0, {{a, d}, {a + φ^-n, d - φ^-n}}, 
1, {{c, d + φ^-n}, {c + φ^-n, d}}, 
2, {{c - φ^-n, b + φ^-n}, {c, b}}, 
3, {{a - φ^-n, b}, {a, b - φ^-n}}]];
Graphics[{EdgeForm[Opacity[.5]],Table[{ColorData[24, k + 1], Rectangle @@gr[k]}, {k, 0, 10}]}]


  • 2
    $\begingroup$ Please don't use JPG for non-photographic images! :) If you look at the edges of your squares, especially at the bottoms of your images, you see strange stripes. This is caused by using JPG (a compressed format designed to be used with photographs) for something that very much isn't a photograph! PNG is the preferred format for illustrations, screenshots, diagrams, etc. (basically any image that isn't a photograph, especially if it contains large, solid-colour regions, text, or discrete curves). $\endgroup$ – Andreas Rejbrand Oct 12 '18 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy