I'm trying to put $N$ cubes on a circle equidistantly. So in the case of 4 cubes, I'd for example like to put the lower left corner of the first cube at $\pi/4$, the lower right of the second cube at $3\pi/4$, the upper right corner of the third one at $5\pi/4$ and the upper left corner of the fourth cube at $7\pi/4$.

Now, my first attempt was as follows

Sq[\[Theta]_, x_] := {Opacity[.3], 
  Cuboid[{Cos[\[Theta]], Sin[\[Theta]], 0}, {Cos[\[Theta]] + 1, 
    Sin[\[Theta]] + 1, x}]}
t1 = Graphics3D[Table[Sq[2 (m - 1)*Pi/4 + Pi/4, 1], {m, 1, 4}]]
t2 = Graphics3D[{Opacity[0.3], Cylinder[]}]
Show[t1, t2]

but as the cylinder shows (and as is to be expected), it is always the lower left corner that is on the circle. Of course this is how cuboid works; you specify the command of the lower left corner. So my question is, is there an easy way around this? I can of course manually shift the position of each cube, but this is a bit annoying, as I'd like my code to work for 3,5,6 and 8 cubes as well.

  • $\begingroup$ "I can of course manually shift the position of each cube, but this is a bit annoying" - why would it be annoying? Just shift both corners by the midpoint of the segment that's joining them. $\endgroup$ Jun 8, 2015 at 10:10
  • $\begingroup$ But can I easily define that for N? I'll have to think about it for a second, see how the math works out. $\endgroup$
    – user129412
    Jun 8, 2015 at 10:15
  • $\begingroup$ Isn't the midpoint just ({Cos[θ], Sin[θ], 0} + {Cos[θ] + 1, Sin[θ] + 1, x})/2? $\endgroup$ Jun 8, 2015 at 10:22
  • $\begingroup$ Well, x gives the height of the cube, but I suppose I could define an angle $\theta_1$ in addition to the current $\theta$ (which I would then give a subscript of 0) which is actually the second angle, and then it can calculate this addition. I suppose I could work something out with that, I'll have a look. $\endgroup$
    – user129412
    Jun 8, 2015 at 10:25
  • $\begingroup$ Hm, this is still quite difficult I think, as each shift has to be calculated simultaneously. $\endgroup$
    – user129412
    Jun 8, 2015 at 10:45

1 Answer 1



cb[p_, d_] := Cuboid[p, p + d {1, 1, 1}]
cn[c_, d_, a_] := Rotate[cb[c + {-d/2, -d/2, 0}, d], a, {0, 0, 1}, c]
func[n_, d_] := 
 Graphics3D[{cn[{(1 + d/2) Cos[#], (1 + d/2) Sin[#], 0}, d, #] & /@ 
    Range[Pi/n, 2 Pi - Pi/n, 2 Pi/n], 
   Cylinder[{{0, 0, 0}, {0, 0, d}}]}, Boxed -> False, Axes -> False, 
  Background -> Black]


Manipulate[func[n, d], {n, Range[4, 10]}, {d, 0.2, 1}]

enter image description here

  • $\begingroup$ This is most definitely nice. However, it no longer has the input $x$ (z would have made more sense) which gives the height of the cuboid. This is most definitely an oversight of mine, and I am sorry for not stating this explicitly in the question. I do think that one can fix this by changing the cb function to Cuboid[p, p + d {1, 1, 0} + {0,0, x}] though, right? Seems to work out in my trial. On second thought though, it might not be that simple. I'll have to take a closer look. $\endgroup$
    – user129412
    Jun 8, 2015 at 12:53
  • $\begingroup$ @user129412 I do not understand your comment. Your title states 'cubes'...self evidently d is the length of side of cube, hence height, if the cube position need to be adjusted adjust the centroid of cube, the first argument of cn. I leave you to find your own solutions or derive inspiration from the better answers of others. $\endgroup$
    – ubpdqn
    Jun 8, 2015 at 13:02
  • $\begingroup$ Yes, you are right, it is a mistake in my wording. I do think however that I can solve it on my own with your solution, and the question is more interesting in the way it is phrased now. $\endgroup$
    – user129412
    Jun 8, 2015 at 13:03
  • $\begingroup$ One thing I cannot seem to find out somehow, is the relation between n and the value of d for which all cubes exactly touch. This is bound to be analytic, but somehow the calculation does not appear all that trivial. Completely separate to the question of course, but an interesting aspect of your solution $\endgroup$
    – user129412
    Jun 8, 2015 at 16:22
  • $\begingroup$ @user129412 Not sure how to do this in mathematica, but if you work out what arc each box will take up for any given value of d, it becomes rather simple. I think d=tan(2*Pi/N)*diameter would do it. $\endgroup$
    – Brilliand
    Jun 8, 2015 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.