Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

If I have the following graphic:

Rotate[Show[{
   Graphics@Line[{{0, 0}, {0, 1}}], 
   Graphics@Line[{{0, 0}, {1, 1}}], 
   Graphics@Plot[x^2, {x, -1, 1}, Axes -> False]}], Pi/3]

It looks like this:

enter image description here

I only want to rotate the content of the graphics, not the frame.

Normally you would use Graphics after rotate, however this doesn't work:

Graphics@Rotate[Show[{
  Graphics@Line[{{0, 0}, {0, 1}}], 
  Graphics@Line[{{0, 0}, {1, 1}}], 
  Graphics@Plot[x^2, {x, -1, 1}, Axes -> False]}], Pi/3]
(* Error: Graphics is not a Graphics primitive or directive. *)
share|improve this question
3  
OT: Does anyone else also think that the design of Rotate and associates is somewhat unfortunate? –  Yves Klett Jan 28 '13 at 13:23

5 Answers 5

up vote 7 down vote accepted

I think your biggest problem is, that Plot already creates a Graphics object, which cannot be set inside another Graphics. Why don't you extract the contents of your plotted Graphics?

Graphics@Rotate[{Line[{{0, 0}, {0, 1}}], Line[{{0, 0}, {1, 1}}], 
   First@Plot[x^2, {x, -1, 1}, Axes -> False]}, Pi/3]

enter image description here

share|improve this answer

You can also use MapAt to apply rotations (or other transformations) on parts at position {1} of a graphics object.

g = Show[{Graphics@Line[{{0, 0}, {0, 1}}],   Graphics@Line[{{0, 0}, {1, 1}}],
Plot[x^2, {x, -1, 1}, Axes -> False]}, ImageSize -> 300];
Row[{g, MapAt[Rotate[#, Pi/3] &, g, {1}]}]

enter image description here

 g2 = Graphics[{Line[{{0, -1/2}, {0, 1}}], {Thick, Blue, 
 Line[{{0, -1/2}, {1, 1}}]}, {Opacity[.5, Red], 
 Disk[{-1/4, 2/3}, {1/2, 1/4}, {-Pi/3, Pi}]}, 
 Plot[x Sin[6 x + 4], {x, -1, 1}, Axes -> False, PlotStyle -> {Thickness[.02], Orange}][[1]]},
 ImageSize -> 300];
 Row[{g2, MapAt[Rotate[#, Pi/3] &, g2, {1}]}]

enter image description here

Applying Rotate to individual parts:

 Grid[Partition[Column[{Row[{"Rotate  ", #}],
  MapAt[Rotate[#, Pi/3] &, g2, {1, #}]}, Center] & /@
  {All, 1, 2, 3, 4, {1, 3}, {1, 4}, {2, 3}, {3, 4}}, {3}],
 Dividers -> All, ItemSize -> {25, 20}, Alignment -> Top]

enter image description here

Other transformations:

 g2B = MapAt[ GeometricTransformation[#, 
  ReflectionTransform[{Cos[Pi/3], Sin[Pi/3]}]] &, g2, {1, 4}];
 Row[{g2, g2B, Show[g2, g2B]}]

enter image description here

 g2C = MapAt[ GeometricTransformation[#, 
 ShearingTransform[Pi/4, {1, 0}, {0, 1}]] &, g2, {1, 4}];
 Row[{g2, g2C, Show[g2, g2C]}]

enter image description here

share|improve this answer

It is not necessary to wrap each Line into a Graphics statement. Same holds for Line which can take more than two points as argument.

To rotate the lines you have to transform the coordinates, not the final output box. Here I use the general command GeometricTransform:

Graphics@GeometricTransformation[
  Line[{{{0, 0}, {0, 1}}, {{0, 0}, {1, 1}}}], RotationTransform[Pi/3]]

enter image description here

share|improve this answer
    
However I actually have other functions in show than Line, for example Plot and Circle, so I can't do this. –  Tyilo Jan 28 '13 at 13:01

You can also get the desired result without GeometricTransformation by putting the Rotate inside the Graphics but before Line:

Graphics@Rotate[Line[{{{0, 0}, {0, 1}}, {{0, 0}, {1, 1}}}], Pi/3]

enter image description here

share|improve this answer
    
I'm using other Graphics types than Line, so this won't work. –  Tyilo Jan 28 '13 at 13:02
    
Then please edit your post with an example that does not work like this. I'm pretty sure we can find a very similar solution to that. ;) –  einbandi Jan 28 '13 at 13:07
    
I have updated the question. –  Tyilo Jan 28 '13 at 13:12

The Presentations Application (I'm the author) is, I believe, much more convenient and intuitive for doing this kind of thing. Curves and primitives such as Line are all treated on the same level. No need to repeatedly jump between graphics levels. The transform operations have also been repackaged as postfix operators. You can rotate all the primitives as a group inside of the Draw2D wrapper (similar to Show). Everything is rotated inside of the frame. So this operation looks like the following:

<< Presentations`

Draw2D[
 {{Draw[x^2, {x, -1, 1}],
    Line[{{0, 0}, {1, 1}}],
    Line[{{0, 0}, {0, 1}}]} // RotateOp[\[Pi]/3]},
 PlotRange -> All,
 ImageSize -> 250
 ]

enter image description here

With rotation you may want to specify the center of rotation as a second argument in the RotateOp statement.

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.