1
$\begingroup$

Subject says it all: I don't seem to be understanding how Mathematica's functions for rotating 3D objects work. Below is a simple example: What I want to do is rotate the cube in the example around an axis normal to the view vector through the center of the cube. What I expect to see is a "spinning" cube, at a fixed position and size. Here is my code:

cgxt[t_] := 
  Graphics3D[Rotate[{EdgeForm[], 
             Hue[30,100,100],               
             Cuboid[{1,1,1} - 1/2, {1,1,1} + 1/2]}, 
             -t Degree, {1, -1, 0}, {1, 1, 1}], 
             Lighting -> {{"Ambient", RGBColor[0.7, 0.7, 0.7]},
                          {"Directional", RGBColor[0.7, 0.7, 0.7],             
             ImageScaled[{0, 5, 0}]}}, Boxed -> False];

which I then demonstrate with

Manipulate[Show[cgxt[t], ViewPoint -> {1000, 1000, 1000}], {t, 0, 180}]

This does not have the desired effect: It looks like the cube is rotated around some off-center axis, changing size as it does so. Interestingly, this effect does not seem to change if I change the location of my cube or the location of the rotation axis independently.

Can someone explain to me what I am missing?

Note (added after discussion below): The following function works as expected, but it's still unclear to me why Mathematica does what it does.

cgxt2[t_] := 
      Graphics3D[Rotate[{EdgeForm[], 
                 Hue[30,100,100],               
                 Cuboid[{1,1,1} - 1/2, {1,1,1} + 1/2]}, 
                 -t Degree, {1, -1, 0}, {1, 1, 1}], 
                 Lighting -> {{"Ambient", RGBColor[0.7, 0.7, 0.7]},
                              {"Directional", RGBColor[0.7, 0.7, 0.7],             
                 ImageScaled[{0, 5, 0}]}}, Boxed -> False, 
                 PlotRange -> 2 size {{-1, 1}, {-1, 1}, {-1, 1}}];
$\endgroup$
1
$\begingroup$
cgxt[t_] := With[
   {
    viewpoint = {1000, 1000, 1000},
    center = {1, 1, 1},
    size = 1,
    rotvec = {1, -1, 0}
    },
   Graphics3D[
    Rotate[
     {
      EdgeForm[],
      Hue[30, 100, 100],
      Cuboid[
       Sequence @@ Outer[Plus, {1, -1} size/2, center]
       ]
      }
     , -t Degree
     , rotvec
     , center
     ]
    , Lighting -> {
      {"Ambient", RGBColor[0.7, 0.7, 0.7]},
      {"Directional", RGBColor[0.7, 0.7, 0.7], ImageScaled[{0, 5, 0}]}
      }
    , Boxed -> False
    , ViewPoint -> viewpoint
    , PlotRange -> center + 1.5 size {{-1, 1}, {-1, 1}, {-1, 1}}
    ]
   ];

Manipulate[
 cgxt[t]
 , {t, 0, 180}
 ]

enter image description here

$\endgroup$
  • $\begingroup$ Hmm, thanks, this helps. Turns out that relative to my code above, all that's needed is that PlotRange option. Not very intuitive, in my book. Do you know what the rationale behind those strange changes in the plot range are that Mathematica seems to be using by default? $\endgroup$ – Pirx Jul 26 '18 at 18:26

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.