Message Boards Message Boards

Trying to rotate 3D Plot (using Rotate and ImageRotate)

Posted 9 years ago

Hello!

I am trying to use ImageRotate to rotate my image by Pi/3 around a specific axis. Here's what I'm trying to do. First I make a 3D plot:

a = SphericalPlot3D[1, {\[Theta], 0, \[Pi]}, {\[Phi], 0, 2 \[Pi]}, 
  ColorFunction -> 
   Function[{x, y, z, \[Theta], \[Phi], r}, 
    ColorData["DarkRainbow"][
     E^-((\[Theta] - \[Pi]/2)^2/(2 \[Sigma]) + (\[Phi] - \[Pi])^2/(
        2 \[Sigma]))]], ColorFunctionScaling -> False, Mesh -> True, 
  Boxed -> False, Axes -> False, PlotPoints -> 150, 
  ViewPoint -> {-2, 0, 0}, ImageSize -> 300]

enter image description here

Now I can rotate it using ImageRotate:

ImageRotate[a, Pi/3]

enter image description here

But now if I try and rotate around a specific axis (exactly the same way as the documentation), I get an error message:

ImageRotate[a, {Pi/3, {1, 0, 0}}]
 ImageRotate::imgang: Angle {\[Pi]/3,{1,0,0}} should be a real number, one of Top, Bottom, Left, Right, or a rule from one to another. >>

Also I tried using Rotate a similar thing happens i.e. I can do it without choosing an axis:

Rotate[a,Pi/3}

enter image description here

But I get an error if I do

Rotate[a,Pi/3,{1,0,0}]
Coordinate {1, 0, 0} should be a pair of numbers, or a Scaled or Offset form.

Does anybody why this is happening?

Thank you!

4 Replies

Mathematica distinguishes between "Images" and "Graphics". See the documentation for information about them.

ImageRotate is for Images, but SphericalPlot3D produces a Graphic.

There is a specific function for Graphics rotation: https://reference.wolfram.com/language/ref/Rotate.html

Rotate[a, Pi/2, {0, 0, 1}]

Another way to do this is to use the ViewPoint option: http://reference.wolfram.com/language/ref/ViewPoint.html

POSTED BY: Sean Clarke

Thanks for the reply Sean!

As mentioned above, I did also try the "Rotate" function as such:

Rotate[a,Pi/3,{1,0,0}]

And I got the error:

Coordinate {1, 0, 0} should be a pair of numbers, or a Scaled or Offset form.

Any idea why?

Thanks!

Posted 8 years ago

Hi there All, I have a related problem, but first I would like to say to @Rajiv Krishnakumar, Mathematica is already answering part of your question and is asking you to give only a 2D vector, or pair of numbers, although the help of the rotate function states that you can give a 3D Vector, it is confusing. I have not discovered yet how to use the Rotate and the Show function for a 3D Graphic, can anyone tell me how to Rotate a 3D Graphic and the combine the rotated Graphic with other 3D Graphics? .

Graph1 = ListContourPlot3D[ Table[x^2 + y^2 - z^2 + RandomReal[0.1], {x, -2, 2, 0.2}, {y, -2, 2, 0.2}, {z, -2, 2, 0.2}], Contours -> {0}, Mesh -> None] Head[Graph1]= Graphic3D

If Rotate is used Esta= Rotate[Graph1, Pi/2] the Head of the Output gets changed to rotate Head[Esta] = Rotate and the rotated Graphic can NOT be combined with other Graphics with Show. The conversion to Graphic with Show is also not possible and delives the "error" message: Show[Esta] Show::gtype: Rotate is not a type of graphics. >> No luck also with function->Graphics Graphics[Esta] Does anyone can help with this Problem?

Thanks in advance for your help Wishing you All Joy and Happiness

POSTED BY: Juan Tamara
Posted 8 years ago

Hello,

Rotate works on graphics primitives (Sphere, Cylinder, Cuboid ...). ListContourPlot3D is not a graphics primitive.

In 3D, Rotate can rotate around any given 3D vector. Check this:

 Manipulate[
   Show[
     Graphics3D@Sphere[],
     Graphics3D@Rotate[Cuboid[], angle, {1, 0, 0}],
     PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}, {-1.5, 1.5}}
   ],
   {{angle, 0}, -\[Pi], \[Pi]}
 ]
POSTED BY: Hans Milton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract