# How to plot rectangles aligned by their center?

Supose I have a rectangle which area is $x^2$. In some cases I may not know what is the size of each side, for $x=12,$ we have several possibilites:

{{144, 1}, {72, 2}, {48, 3}, {36, 4}, {24, 6}, {18, 8}, {16, 9}, {12,
12}, {9, 16}, {8, 18}, {6, 24}, {4, 36}, {3, 48}, {2, 72}, {1, 144}}


I want to plot each one of these rectangles, all them aligned by their center.

Until now, I did this:

n = 144;
a = Select[n/Range[1, n], IntegerQ];
b = Reverse[a];
c = Table[{a[[x]], b[[x]]}, {x, 1, Length[a]}]


Which finds all the sizes of the sizes which satisfy $a\cdot b=x^2$. But I can't figure out how to do the next part, can you help me?

• To find all side pairs: {a, b} /. Solve[a b == 144 && a > 0 && b > 0, Integers] – Vitaliy Kaurov Sep 13 '12 at 10:06
• Everyone is so busy answering.. no one votes the question up? – halirutan Sep 13 '12 at 10:40
• Gustavo, I see that you have not Accepted an answer to this question. Did you forget or are they all unsatisfactory in some way? – Mr.Wizard Feb 12 '13 at 18:32
• @Mr.Wizard Oh sorry. I forgot. – Billy Rubina Feb 13 '13 at 5:09
• Well, thanks for the Accept. – Mr.Wizard Feb 13 '13 at 23:43

This seems too simple to really be what you're asking but perhaps:

recs = {{144, 1}, {72, 2}, {48, 3}, {36, 4}, {24, 6}, {18, 8}, {16,
9}, {12, 12}, {9, 16}, {8, 18}, {6, 24}, {4, 36}, {3, 48}, {2,
72}, {1, 144}};

Rectangle[-#/2, #/2] & /@ recs // Graphics You should also look at Divisors.

• But what I want is really simple, also thanks for refreshing my memory on the Divisors. – Billy Rubina Sep 13 '12 at 10:02
• If you'd like you can make my answer a part of yours - I'll delete mine then. – Vitaliy Kaurov Sep 13 '12 at 10:47

This is based on @Mr.Wizard answer , just trying to improve presentation:

First of all you can find all your sides as:

recs = {a, b} /. Solve[a b == 144 && a > 0 && b > 0, Integers];


Then lets clearly distinguish rectangles:

Manipulate[Graphics[{EdgeForm[{Opacity[.2], Thickness[.001], Black}], Blue,
Opacity[op], Rectangle[-#/2, #/2] & /@ recs[[1 ;; re]]}, PlotRange -> pl],
{{op, .2, "opacity"}, 0, 1, Appearance -> "Labeled"},
{{pl, 16, "zoom"}, 1, 75, Appearance -> "Labeled"},
{{re, Length[recs], "number"}, 1, Length[recs], 1, Appearance -> "Labeled"}] Try!

Graphics[{EdgeForm[Black], FaceForm[Hue[RandomReal[]]],
Rectangle[{0, 0}, #]} & /@ c, Frame -> True,
GridLines -> Automatic, GridLinesStyle -> Directive[Orange, Dashed]] • Oh, It's also a nice visualization. – Billy Rubina Sep 13 '12 at 10:09

It seems I understood your requirement somewhat differently from others, so this is what I came up with:

GraphicsGrid[{Graphics@Rectangle[{0, 0}, #] & /@ c}] Graphics[Rectangle[…]] plots each rectangle in list c, without any consideration for alignement. Then let GraphicsGrid do the alignment for you…

Edit: and I can has color too: Also based on @Mr.W's answer and taking up his suggestion (using Divisors):

ClearAll[rectangles];
rectangles = Function[{x}, {-#/2, #/2} & /@ ({x^2/#, #} & /@ Divisors[x^2])];
grphcs :=  Graphics[{Directive[Hue[RandomReal[]], EdgeForm[Opacity[.3]],
FaceForm[Opacity[.3]]], Rectangle[Sequence @@ #]} & /@ #, ImageSize->300] &

Row[grphcs@rectangles[#] & /@ {2,3,4,5}] Row[grphcs@rectangles[#] & /@ {9, 10, 12}] 