# Frame shifting when drawing rotated and shifted arrows

I am experiencing a problem that a left margin is added to my Graphics if I include an arrow that is rotated by 3Pi/4 and shifted by -1. And only for those values. Here is a demo of my problem:

Grid[Table[
Translate[Rotate[Arrow[{{-1/2, 0}, {1/2, 0}}], phi], shift],
Line[{{-1.7, 0}, {1.7, 0}}],
Line[{{-1, -1.7}, {-1, 1.7}}]
}}, AspectRatio -> 1, ImageMargins -> 0],
{phi, 0, 3 Pi/4, Pi/4},
{shift, {{1, 0}, {0, 1}, {-1, 0}}}
],
Frame -> All]


The lines are just to ensure that the bounding box of the resulting graphics remains unchanged. Here is the output:

All graphics are centered and have a symmetric margin, apart from the bottom-left one. Probably related is that arrows by themselves apparently do not rotate around the center of their bounding box:

Grid[{Table[Graphics[{Thick, Arrowheads[0.1], {
Rotate[Arrow[{{-1/2, 0}, {1/2, 0}}], phi]
}}, AspectRatio -> 1],
{phi, 0, 3 Pi/4, Pi/4}]
},
Frame -> All]


Note that the arrows in the first image did rotate correctly around their bounding box. For instance, in the bottom-right cell, the center of the rotated and shifted arrow is exactly at the intersection of the two lines, i.e., at (-1,0) as expected from the translation. Still, all these problems disappear if I explicitly specify the rotation center via

Rotate[Arrow[{{-1/2, 0}, {1/2, 0}}], phi, {0, 0}]


Is this a bug?

• You also have a top margin added to the graphic in grid cell {3, 2}. Feb 21 '17 at 7:32

1) The rotations and translations are being made correctly in all the grid cells. It is the plot range that is shifting. I don' know why it only affect two of the cells. It can be fixed by explicitly giving the plot range as well by explicitly giving the rotation center.

Grid[
Table[
Graphics[
{Thick, Orange,
Line[{{-1.7, 0}, {1.7, 0}}], Line[{{-1, -1.7}, {-1, 1.7}}],
{Translate[Rotate[Arrow[{{-1/2, 0}, {1/2, 0}}], phi], shift]}},
PlotRange -> {{-1.7, 1.7}, {-1.7, 1.7}},
ImageMargins -> 0],
{phi, 0, 3 Pi/4, Pi/4},
{shift, {{1, 0}, {0, 1}, {-1, 0}}}],
Frame -> All]


2) If you think the grid you made was bad, it is good that you didn't try GraphicsGrid which really makes a mess.

GraphicsGrid[
Table[
Graphics[
{Thick, Orange,
Line[{{-1.7, 0}, {1.7, 0}}], Line[{{-1, -1.7}, {-1, 1.7}}],
{Translate[Rotate[Arrow[{{-1/2, 0}, {1/2, 0}}], phi], shift]}},
ImageSize -> 167,
ImageMargins -> 0],
{phi, 0, 3 Pi/4, Pi/4},
{shift, {{1, 0}, {0, 1}, {-1, 0}}}],
Frame -> All]


This too is fixed by explicitly giving the rotation center or the plot range.

### Update

I reported both problems, both the original one concerning Grid and the one concerning GraphicsGrid. I have received a reply. I quote the relevant sections:

When you put the plots inside a GraphicsGrid, they are put inside individual insets. Unfortunately, there is a known issue with GraphicsGrid failing to determine the optimal size for graphics with insets.

So, I recommend you to avoid using plots along the GraphicsGrid. Meanwhile, you can use the workarounds provided inside the sent notebook and ones on the [Mathematica.SE] thread.

Regarding the slight variations in the image size of the graphics when used along the function Grid, please consider the following.

Mathematica code set the unspecified graphics options such as PlotRange, PlotRangePadding, and ImagePadding, to automatic. Mathematica underlying algorithm updates these option values after each transformation. So the image size might (and in this case will) change as the arrow rotates.

The slight difference in the image size of the graphics causes the irregularity that you observed when using Grid without defining the rotation center or PlotRange explicitly.

I concluded from this that WRI considers the GraphicsGrid behavior a bug, but not the Grid behavior.

• Thanks, this post identifies the core of the problem: PlotRange. Would you consider the behavior a bug? Feb 21 '17 at 20:19
• @Felix. I do think it's a bug. I plan to file a problem report on this topic with WRI tech support. Feb 22 '17 at 5:19
• If WRI doesn't consider this a bug, I think explicitly specifying the plot range should be considered the solution. Thanks for communicating the issue. Feb 28 '17 at 0:30

I never got warm with transforming graphics instead of just doing the calculation on the coordinates themselves. This is a clear example why it can be unnecessarily hard to use this.

If you instead use your exact same approach but transform the coordinates this issue disappears.

Grid[Table[Graphics[{Thick, Arrowheads[0.05], {Arrow[
TranslationTransform[shift][
RotationTransform[phi][{{-1/2, 0}, {1/2, 0}}]]],
Line[{{-1.7, 0}, {1.7, 0}}], Line[{{-1, -1.7}, {-1, 1.7}}]}},
AspectRatio -> 1, ImageMargins -> 0], {phi, 0, 3 Pi/4,
Pi/4}, {shift, {{1, 0}, {0, 1}, {-1, 0}}}], Frame -> All]


Grid[{Table[
Graphics[{Thick,

• @Felix You could always fix the PlotRange but it is not entirely clear why this happens with Arrow. If you replace your Arrow with small Rectangle then the issue doesn't appear. Btw, you can see that your arrows are rotated around the center. The plot range is just off in your example. Feb 21 '17 at 4:02