I would like to have an animation of rotating box and displayed it with other elements (not rotated) using Show. The first step to do that is to have all the elements working properly. So I did the following:

  1. Created a box:

    myBox = Cuboid[{-40, 40, 0}, {40, 60, 10}];

    and make a Graphics3D out of it:

  2. Rotated it:

    Rotate[Graphics3D[myBox], Pi/2, {0, 0}]
  3. Used Show:

    Show[Rotate[Graphics3D[myBox], Pi/2, {0, 0}]]

And the strange things started to happen.

I've got "Show::gtype: Rotate is not a type of graphics.". So I googled and found the following: link1, link2, link3

I tried most of the suggestions from those threads and the only one that helped was halirutan's from the first one:

    Show[Graphics@First@Rotate[Graphics3D[myBox], Pi/2, {0, 0}]]

There was no error, but also no rotation, so the problem was still not solved.

Then I tried:

    First@Show[Graphics@Rotate[Graphics3D[myBox], Pi/2, {0, 0}]]

The image was rotated, but it wasn't Graphics, so I couldn't use Show on it.

I suppose that answer is somewhere in the threads I quoted, but either I missed it or I can't use it.

  • 2
    $\begingroup$ For 3D you need a 3D vector inside Rotate, e.g., Show[Graphics3D[Rotate[myBox, Pi/2, {0, 0, 1}]]] $\endgroup$
    – Karsten 7.
    Mar 17 '15 at 21:49
  • $\begingroup$ What are you trying to achieve by applying Show? $\endgroup$
    – Szabolcs
    Mar 17 '15 at 21:49
myBox = Cuboid[{-40, 40, 0}, {40, 60, 10}];
Show@MapAt[Rotate[#, Pi/4, {0, 0, 1}, {0, 0, 0}] &, Graphics3D[myBox], {1}]

enter image description here

Manipulate[Table[Show[Graphics3D[{Red, Sphere[{0, 0, 0}, 30],
    Green, Cylinder[{{30, 30, 30}, {40, 50, 40}}, 30]}],
    MapAt[Rotate[#, k, v, {0, 0, 0}] &, Graphics3D[myBox], {1}],
    Boxed -> False, PlotRange -> {{-100, 100}, {-100, 100}, {-100, 100}}],
   {k, 0, 2 Pi, Pi/12}] // ListAnimate,
 {{v, {1, 0, 0}}, {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}}]

enter image description here

  • $\begingroup$ Thank you very much, that was exactly what I needed :) $\endgroup$
    – mstechly
    Mar 18 '15 at 20:28

My understanding of the question is that you are not interested in doing a rotation of the 3D object inside the 3D scene, but instead want to do a 2D rotation of the displayed Graphics3D, as if the latter were just another 2D Graphics element.Then you want to combine the result with additional 2D Graphics using Show.

For this task, the right tool is simply to use Inset. Here is an example:

    Graphics3D[myBox, ImageSize -> 300], Pi/4, {0, 0}] ]
 ImageSize -> 300

block rotated

Here I used the same commands as in the question, except to change the rotation angle to something more obviously "rotated". Then I specified ImageSize options for both the Graphics3D and the final Show. This, together with the options for Inset and the choice of PlotRange in Graphics, can be used to place the rotated object arbitrarily. Here I didn't include that because there were no other objects to be displayed. But the Show framework is all you needed, and from there everything works as it always does in Show.

In principle, you can also do away with Rotate completely and use the options of Inset directly to rotate the content in 2D.

  • 1
    $\begingroup$ Looks better if you add the option Boxed -> False option to Graphics3D. You know that, but I think it's worth pointing out to our readers with little Mathematica experience. $\endgroup$
    – m_goldberg
    Mar 18 '15 at 13:34
  • $\begingroup$ I probably still don't understand something. If I want to show it with second box it doesn't work: myBox2 = Cuboid[{-40, 40, 0}, {40, 60, 10}]; Show[Graphics[Inset[Rotate[Graphics3D[myBox1], Pi/4, {0, 0}]]], myBox2] $\endgroup$
    – mstechly
    Mar 18 '15 at 20:31
  • $\begingroup$ Sorry for the second comment, some PC problems. It should have been: Show[Graphics[Inset[Rotate[Graphics3D[myBox1], Pi/4, {0, 0}]]], Graphics3D[myBox2]] @m_goldberg answer helps, but I would like to know why there is an error if I use Show. $\endgroup$
    – mstechly
    Mar 18 '15 at 20:43
  • 1
    $\begingroup$ You can't combine 2D and 3D graphics within a single Show. It's either one or the other, so you have to apply the conversion to 2D to both objects. $\endgroup$
    – Jens
    Mar 18 '15 at 21:05

The answer:

myBox = Cuboid[{-40, 40, 0}, {40, 60, 10}];

Show@MapAt[Rotate[#, Pi/4, {0, 0, 1}, {0, 0, 0}] &, Graphics3D[myBox], {1}]

is a good method.

I have an another way to solve this problem.

myBox = Graphics3D[Cuboid[{-40, 40, 0}, {40, 60, 10}]];

Graphics3D[Rotate[myBox[[1]], Pi/4, {0, 0, 1}, {0, 0, 0}]]

Compare with the above method, it is simpler and easier to understand.

  • $\begingroup$ Keep in mind that myBox[[1]] leave all options myBox could've had while MapAt preserves them $\endgroup$
    – Kuba
    Jan 18 '18 at 12:13
  • $\begingroup$ Yeah, it is mainly used for Show[ the rotation of the graphics ]. Except for rotation, if you want to do something else. It is not necessarily the best. $\endgroup$ Jan 19 '18 at 0:48

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.