Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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[
  Graphics[{Thick, Arrowheads[0.05], {
     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:

enter image description here

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]

enter image description here

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?

share|improve this question
    
You also have a top margin added to the graphic in grid cell {3, 2}. – m_goldberg 3 hours ago

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]

Mathematica graphics

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

Mathematica graphics

share|improve this answer
    
+1 for another option that actually works. However, my approach should also work, shouldn't it? – Felix 6 hours ago
1  
@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. – halirutan 6 hours ago

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}}],
       Black, Arrowheads[0.05], 
       {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]

grid1

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}}],
       Black, Arrowheads[0.05], 
       {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]

grid2

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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