6
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ why do you have Shape[x_] but x is not used any where in the function? $\endgroup$
    – Nasser
    Commented Feb 5, 2022 at 15:40
  • 1
    $\begingroup$ 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 $\endgroup$
    – Bob Hanlon
    Commented Feb 5, 2022 at 16:04
  • $\begingroup$ @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 $\endgroup$
    – Jepessen
    Commented Feb 5, 2022 at 16:16

3 Answers 3

7
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ What if I need a rectangular array (that was the reason of Partition)? $\endgroup$
    – Jepessen
    Commented Feb 5, 2022 at 16:19
8
$\begingroup$

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], {x*1.3, 0}]
    , Black, Translate[Circle[{0.5, 0.5}, 0.7], {x*1.3, 0}]
    }, {x, 0, 10, 1}
   ];
GraphicsGrid[Partition[Graphics /@ exp1, 10]]

enter image description here

$\endgroup$
1
  • 3
    $\begingroup$ +1 Alternatively, you could set the circle`s opacity to 0 $\endgroup$
    – Bob Hanlon
    Commented Feb 5, 2022 at 16:08
7
$\begingroup$

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

$\endgroup$

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.