3
$\begingroup$

Why when I rotate rectangle its size gets bigger? How can I fixed? Thanks.

{n, m} = {2, 3}; ro = 0.6;

SeedRandom[123];
mat = RandomChoice[{{1, 3}, {1, 4}, {2, 3}, {2, 4}}, {n, m}];

mat2 = Table[{{1, 1}, {3, 2}, Flatten[mat, 1][[i]]}, {i, n*m}];

Grid[Partition[
  Which[#[[3]] == {1, 3}, 
     Graphics[{Cyan, Rectangle[#[[1]], #[[2]], RoundingRadius -> ro]}],
     #[[3]] == {1, 4}, 
     Graphics[{Lighter[Blue, 0.5], 
       Rectangle[#[[1]], #[[2]], RoundingRadius -> ro]}],
     #[[3]] == {2, 3}, 
     Graphics[{Cyan, 
       Rotate[Rectangle[#[[1]], #[[2]], RoundingRadius -> ro], 
        90 \[Degree]]}],
     #[[3]] == {2, 4}, 
     Graphics[{Lighter[Blue, 0.5], 
       Rotate[Rectangle[#[[1]], #[[2]], RoundingRadius -> ro], 
        90 \[Degree]]}]] & /@ mat2, m], Spacings -> {0, 0}]

enter image description here

$\endgroup$
2
$\begingroup$

Here is a minimal example showing the issue, and giving a workaround

With[
    {
        rectangle = Rectangle[{1, 1}, {3, 2}],
        rotation = Rotate[#, 90 Degree]&
    },
    Row @ {
        Graphics @ rectangle,
        Graphics @ rotation @ rectangle,
        rotation @ Graphics @ rectangle
    }
]

enter image description here

$\endgroup$
  • $\begingroup$ So, order matters. Thanks. It worked excellently. $\endgroup$ – OkkesDulgerci Nov 21 '17 at 16:34
3
$\begingroup$

The easiest way is to set the image size directly. E.g.,

{n, m} = {2, 3}; ro = 0.6;
SeedRandom[123];
pts = RandomChoice[{{1, 3}, {1, 4}, {2, 3}, {2, 4}}, n*m]
mat2 = Map[{{1, 1}, {3, 2}, #} &, pts]
f[pt_] := With[{
   row1 = {1, 1},
   row2 = {3, 2},
   color = <|3 -> Cyan, 4 -> Lighter[Blue, 0.5]|>[Part[pt, 2]],
   angle = <|1 -> 0, 2 -> 90 Degree|>[Part[pt, 1]]
   },
  Graphics[{color, 
    Rotate[Rectangle[row1, row2, RoundingRadius -> ro], angle]},
   ImageSize -> {100, 100}]
  ]
Grid[Partition[f /@ pts, m], Spacings -> {0, 0}]

enter image description here

$\endgroup$

Your Answer

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

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