Message Boards Message Boards

0
|
12290 Views
|
9 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Rotate the coordinate system

Posted 9 years ago

Hello everybody

I like to plot following graphic: enter image description here

Basically I have two coordinate systems. Coordinate system "A" which is not tilted and a coordinate system "B" which is rotated at the origin by an angle alpha. In coordinate system "B" I plot the cos-function which seems rotated when looking from coordinate system A. The gray shaded area which you can see in the picture is not important.

How can I plot this? I have no idea :-(. I already tried it with the Mathematica-function Rotate.

Hope you can help me to solve this problem. Thank you very much.

POSTED BY: Peter Parker
9 Replies

Great, thank you guys for your help. I really appreciate it.

Best regards,

Peter

POSTED BY: Peter Parker

Hi Peter,

I think the resolution in both images is the same, but the rotated image contains necessarily more pixels:

In[10]:= ImageDimensions /@ {img0, img1}
(*  Out[10]= {{500, 300}, {547, 392}}  *)

enter image description here

But as a matter of fact Ottos solution is much more elegant! One just has to make sure that in both plots the same options are used:

pArgs = Sequence[{x, -2*\[Pi], 2*\[Pi]}, PlotRange -> {-3, 3}, ImageSize -> 500];
Plot[x, Evaluate @ pArgs, PlotStyle -> {Opacity[0]}, 
 Epilog -> Inset[Rotate[Plot[Cos[x], Evaluate @ pArgs], -10 Degree]]]

Regards -- Henrik

POSTED BY: Henrik Schachner

Hello

Thank you Henrik for your answer. Now it is perfectly working. I am wondering why the resolution of the tilted coordinate system is much lower than the other one. Should't Mathematica be able to rotate an image without decreasing the resolution? Maybe this is the advantage of Ottos solution.

Regards,

Peter

POSTED BY: Peter Parker

Hi Henrik and Otto

Thank you very much. I like both of your solutions.

@Henrik: If I copy-paste your code I get following error message: The number of channels must be equal or one of them must be a single-channel image and the other a multichannel image.

The problem is related to the last function ImageMultiply. Any ideas what this means and how I can fix that? I am using Mathematica 10.0.

@Otto: I would like to increase the size of the inset but for some reason this doesn't work. I want both coordinate systems with similar frame size (like in Henriks solution). At the moment the inset is much too small for my taste :-)

I tried several options but I failed.

   Plot[0, {x, -6, 6},
    PlotRange -> {{-2, 2}, {-2, 2}},
    Frame -> True,
    PlotStyle -> Black,
    ImageSize -> 800,
    Epilog -> 
     Inset[Rotate[Plot[Cos[x], {x, -2*\[Pi], 2*\[Pi]}], 30 Degree], {0, 
       0}, {0, 0}, 15]
    ]

Thank you very much for your help,

Peter

POSTED BY: Peter Parker

Hi Peter,

sorry for this issue! I still do not fully understand how this could have happened - obviously there was a change from version 9.0 (where I developed my first "solution") to version 10.2 (where I can now verify the problem). Anyway, here is the code which should run for version 10.2; it is even somewhat simpler:

img0 = Plot[0, {x, -10, 10}, PlotRange -> {{-10, 10}, {-5, 5}}, 
   ImageSize -> 500];
img1 = ImageRotate[
   Plot[3 + Sin[x], {x, -10, 10}, PlotRange -> {-5, 5}, 
    PlotStyle -> Green, ImageSize -> 500], -10 \[Degree]];
ImageCompose[img0, img1, {251, 150}]

Regards -- Henrik

POSTED BY: Henrik Schachner

Hello Peter,

This will display the rotated plot:

Rotate[Plot[Cos[x], {x, -2*\[Pi], 2*\[Pi]}], 30 Degree]

However, you only get the rotated axes, not the straight ones. You can put it inside another plot, just to get straight axes:

Plot[0, {x, 0, 1}, PlotRange -> {{-2*\[Pi], 2*\[Pi]}, {-3, 3}}, 
 Epilog -> 
  Inset[Rotate[Plot[Cos[x], {x, -2*\[Pi], 2*\[Pi]}], 30 Degree]]]

You can play with the ranges and the size of the Inset to get things right. I cannot say I like the idea of using an additional call to Plot just to generate axes, but I am not being able to display the output of Rotate with Graphics, even if I first evaluate FullGraphics on it. If you could display it with Graphics, then you could display the straight axes and even a frame, if desired.

You may want to see:

http://mathematica.stackexchange.com/questions/80505/how-to-plot-functions-in-multiple-coordinate-systems

and

http://mathematica.stackexchange.com/questions/1003/is-there-an-equivalent-of-fullgraphics-for-graphics3d

OL.

POSTED BY: Otto Linsuain

Hi Peter,

here comes a crude approach, but maybe this goes in the right direction:

img0 = Image@
   RotateLeft[ (* `RotateLeft` is for fine tuning ... *)
    ImageData@
     ColorConvert[
      Plot[0, {x, -10, 10}, PlotRange -> {{-10, 10}, {-4, 4}}, 
       ImageSize -> 500], "Grayscale"], {0, 2}];

img1 = ImageRotate[
   Plot[3 + Sin[x], {x, -10, 10}, PlotRange -> {-4, 4}, 
    PlotStyle -> Green, ImageSize -> 500], -10 \[Degree], 
   Background -> White];

ImageMultiply[img1, img0]

which gives:

enter image description here

Regards -- Henrik

POSTED BY: Henrik Schachner

Hi

thank you Otto for your answer. This is only partially what I am looking for. The code that you gave me shows a cos-function rotated by an angle. Now I would like to have a second coordinate system on top of this plot which is rotated by the same angle. Just like in the picture I included in my first post. That is the big challenge for me.

Best regards,

Peter

POSTED BY: Peter Parker

Hello Peter,

Not sure whether this is what you are looking for. At least I hope it will provide a starting point:

ParametricPlot[
 Evaluate[Dot[RotationMatrix[\[Pi]/12], {x, Cos[x]}]], {x, -2*\[Pi], 
  2*\[Pi]}]

Not sure how to paste the image but it looks like a rotated cosine graph. Notice that the default AspectRatio for ParametricPlot is Automatic, meaning the horizontal and vertical scales are equal. This is different than the default value in Plot. This may become important if you want to display them together.

OL.

POSTED BY: Otto Linsuain
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