6

I've the following snippet, simplified from a more complex code:

Shape[x_] := Rectangle[
  {0, 0},
  {1, 1},
  RoundingRadius -> 0.1
  ]

exp1 = Table[ { EdgeForm[Black], Hue[Sqrt[x]], Translate[ Rotate[ Shape[x], x ], {x*1.3, 0} ] }, {x, 0, 10, 1} ]; GraphicsGrid[Partition[Graphics /@ exp1, 10]]

This is the output:

Output

How can I maintain the size of rectangles during the rotation? I'd like them to have all the same size.

Jepessen
  • 950
  • 6
  • 16
  • why do you have Shape[x_] but x is not used any where in the function? – Nasser Feb 05 '22 at 15:40
  • 1
    The Partition is discarding the last element of the Table. To retain that element use GraphicsGrid[{Graphics /@ exp1}] If the discard is intentional, additionally change the upper bound on the Table to 9 – Bob Hanlon Feb 05 '22 at 16:04
  • @Nasser because Shape must represent a generic shape depending on the variable. In this particular example is not dependent from X because it was not the focus of the question, but I shoulr be able to use other shapes dependent on X – Jepessen Feb 05 '22 at 16:16

3 Answers3

8

Translate a circle to the same location. Set the color of the circle to White and you will have what you are looking for. I am sure there are more formal solutions available.

Shape[x_] := Rectangle[{0, 0}, {1, 1}, RoundingRadius -> 0.1]

exp1 = Table[{ EdgeForm[Black], Hue[Sqrt[x]], Translate[Rotate[Shape[x], x], {x1.3, 0}] , Black, Translate[Circle[{0.5, 0.5}, 0.7], {x1.3, 0}] }, {x, 0, 10, 1} ]; GraphicsGrid[Partition[Graphics /@ exp1, 10]]

enter image description here

Syed
  • 52,495
  • 4
  • 30
  • 85
7

The different sizes are created by the unnecessary "GraphicsGrid" that scales the different pictures. Without it:

SimplifyShape := Rectangle[{0, 0}, {1, 1}, RoundingRadius -> 0.1]
exp1 = Table[{EdgeForm[Black], Hue[Sqrt[x]], 
    Translate[Rotate[SimplifyShape, x], {x*1.5, 0}]}, {x, 0, 10, 1}];
exp1 // Graphics

enter image description here

Update

If you want an "regular array", that is a vector, of images the same size, use RotateImage:

exp1 = Table[
   ImageRotate[
    Graphics[{EdgeForm[Black], Hue[Sqrt[x]], SimplifyShape}], x, 
    Background -> Transparent], {x, 0, 10, 1}];
exp1

enter image description here

Daniel Huber
  • 51,463
  • 1
  • 23
  • 57
7

Specify ImageSize in each Graphics using the (still undocumented) syntax ImageSize -> 1 -> size (which makes 1 unit in user units correspond to size points in rendered image) :

GraphicsGrid[Partition[Graphics[#, ImageSize -> 1 -> 50] & /@ exp1, 10]]

enter image description here

Compare with

GraphicsGrid[Partition[Graphics[#, ImageSize -> 50] & /@ exp1, 10]]

enter image description here

Using with symbolic sizes:

Table[Labeled[GraphicsGrid[
      Partition[Graphics[#, ImageSize -> is] & /@ exp1, 10]], 
    Style[ImageSize -> is, 24], Top],
  {is, {5/3 -> Tiny, 3 -> Small, 6 -> Medium, 6 -> Automatic, 9.5 -> Large}}] //
 Column[#, Dividers -> All] &

enter image description here

Use the 1st and 8th parts of exp1 to compare the results of two ways of specifying image size. Note how the spec ImageSize -> 1 -> size modifies the actual image size so that an object with a length of 1 user unit rendered as size pixels long:

Row[Labeled[#, Column[{"ImageDimensions:", ImageDimensions @ #}, Center], Top] & @ 
   Graphics[#, ImageSize -> 1 -> 200] & /@ exp1[[{1, 8}]]]

enter image description here

versus

Row[Labeled[#, Column[{"ImageDimensions:", ImageDimensions @ #}, Center], Top] & @
  Graphics[#, ImageSize -> 200] & /@ exp1[[{1, 8}]]]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896