7

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. *)
wxffles
  • 14,246
  • 1
  • 43
  • 75
Tyilo
  • 1,545
  • 13
  • 25

5 Answers5

8

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

halirutan
  • 112,764
  • 7
  • 263
  • 474
6

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

kglr
  • 394,356
  • 18
  • 477
  • 896
3

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

Markus Roellig
  • 7,703
  • 2
  • 29
  • 53
  • 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
2

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

einbandi
  • 4,024
  • 1
  • 23
  • 39
1

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.

David Park
  • 2,613
  • 18
  • 14