Group Abstract Group Abstract

Message Boards Message Boards

0
|
9.5K Views
|
5 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Plot a function (x,y) in polar coordinates?

Posted 9 years ago

Hi, I've this function f(x,y) such that (x,y) are the coordinates of an ellipse, that is (x/a)^2 + (y/b)^2 = 1.......so like the function yields an output for all coordinates of the ellipse....I want the plot in polar coordinates, like I want to have all the outputs laid down on a circular plot with degrees shown all around and the values of f(x,y)...i've absolutley no idea how to do this so please help me out from the basics, as i'm new to mathematica...

POSTED BY: Muhammad Abbas
5 Replies
POSTED BY: Marco Thiel

Or even, yet simpler:

equation=(x/a)^2+(y/b)^2==1;
equation=equation/.{a->2,b->3}

plot=ContourPlot[Evaluate[equation],{x,-6,6},{y,-6,6},PlotPoints->100,Axes->False,Frame->False];
plot2=PolarPlot[3,{\[Phi],0,2\[Pi]},PlotStyle->None,PlotRange->5,PolarAxes->Automatic,PolarTicks->{"Degrees",Automatic}];
Show[{plot2,plot}]
POSTED BY: Sander Huisman

of course one does not have to go back and forth polar coordinates if one has the equation in cartesian coordinates:

equation=(x/a)^2+(y/b)^2==1;
equation=equation/.{a->2,b->3}

plot=ContourPlot[Evaluate[equation],{x,-6,6},{y,-6,6},PlotPoints->100];
lines=Cases[Normal[plot],Line[_],\[Infinity]];
max=Max[Cases[lines,(x:{_?NumericQ,_?NumericQ}):>Norm[x],\[Infinity]]];
PolarPlot[1.2max,{\[Phi],0,2\[Pi]},Epilog->lines,PlotStyle->None,PlotRange->5,PolarAxes->Automatic,PolarTicks->{"Degrees",Automatic}]

giving the same plot...

POSTED BY: Sander Huisman

great answer, as always!

The transformation rules can also be obtained like this:

rules = Thread[{x, y} -> CoordinateTransform[{"Polar" -> "Cartesian", 2}, {r, \[Phi]}]]

which might be easier to grasp...

Another new way of doing the entire thing, including the polar axes is:

equation=(x/a)^2+(y/b)^2==1;
equation=equation/.{a->2,b->3}

rules=Thread[{x,y}->CoordinateTransform[{"Polar"->"Cartesian",2},{r,\[Phi]}]];
equation=equation/.rules;

plot=ContourPlot[Evaluate[equation],{r,0,6},{\[Phi],-\[Pi]+10^-8,\[Pi]},PlotPoints->100];
lines=Cases[Normal[plot],Line[x_]:>Line[FromPolarCoordinates[x]],\[Infinity]];
max=Max[Cases[lines,(x:{_?NumericQ,_?NumericQ}):>Norm[x],\[Infinity]]];
PolarPlot[1.2max,{\[Phi],0,2\[Pi]},Epilog->lines,PlotStyle->None,PlotRange->5,PolarAxes->Automatic,PolarTicks->{"Degrees",Automatic}]

giving:

enter image description here

POSTED BY: Sander Huisman
POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard