Mathematica can use ContourPlot
to draw implicit Cartesian equations, but doesn't seem to have a similar function to plot an implicit polar equation, for example
$\theta ^2=\left(\frac{3 \pi }{4}\right)^2 \cos (r)$
What's the best way to do this?
Mathematica can use ContourPlot
to draw implicit Cartesian equations, but doesn't seem to have a similar function to plot an implicit polar equation, for example
$\theta ^2=\left(\frac{3 \pi }{4}\right)^2 \cos (r)$
What's the best way to do this?
Since ContourPlot[]
returns a GraphicsComplex
, you could also replace the point list of the plot with g @@@ pointlist
where g
is the coordinate transformation. For example
f[r_, th_] := th^2 - (3 Pi/4)^2 Cos[r]
g[r_, th_] := {r Cos[th], r Sin[th]}
pl = ContourPlot[f[r, th] == 0, {r, 0, 8 Pi}, {th, 0, 2 Pi}, PlotPoints -> 30];
pl[[1, 1]] = g @@@ pl[[1, 1]];
Show[pl, PlotRange -> All]
which produces
The advantage of this method is that it also works for coordinate transformations for which the inverse transformation is hard to find.
AspectRatio -> Automatic
in Show
so that this "looks nice."
$\endgroup$
Commented
Jan 24, 2012 at 14:20
pl[[1, 1, 1]] = g @@@ pl[[1, 1, 1]];
$\endgroup$
Does this
ContourPlot[
Evaluate@With[
{r = Sqrt[x^2 + y^2],
θ = ArcTan[x, y]},
θ^2 - Cos[r] == 0
],
{x, 0.1, 4 Pi}, {y, 0, 4 Pi}
]
work?
Plot:
ContourPlot
substitution, this is something I tried originally but couldn't get to work.
$\endgroup$
Commented
Jan 23, 2012 at 21:17
If you allow negative radii, there's another entire half of the solution:
PolarPlot[
Evaluate[Flatten[
Table[{-ArcCos[(16 t^2)/(9 Pi^2)], ArcCos[(16 t^2)/(9 Pi^2)]} + k 2 Pi,
{k, -2, 2}]
]],
{t, -Pi, Pi},
PlotStyle -> Table[Directive[Thick, Hue[i/10]], {i, 10}]
]
You can do something like this:
ContourPlot[ArcTan[x,y]^2 == (3 Pi/4)^2 Cos[Sqrt[x^2 + y^2]],
{x, -23, 23}, {y, -23, 23}, ContourStyle -> Directive[Thick, Orange]]
All the other three solutions use ContourPlot
. Here's a solution using PolarPlot
.
PolarPlot[{ArcCos[#2^2/(3 π/4)^2] + 2 π #1,
-ArcCos[#2^2/(3 π/4)^2] + 2 π (#1 + 1)} & @@ QuotientRemainder[Abs@ θ, 2 π],
{θ, -7 π, 8 π}, PlotStyle -> {Thick, Darker@Green}]
This makes use of the fact that the solution to $\theta^2=\displaystyle\left(\frac{3\pi}{4}\right)^2\cos(r)$ is
$$r=\pm\arccos\left(\frac{16\theta^2}{9\pi^2}\right)+2\pi n,\ n\in\mathbb{Z}$$
My question seems a duplicate of this one. And cvgmt's answer works as well.
ContourPlot[\[Theta]^2 == ((3 \[Pi])/4)^2 Cos[r], {r, -20,
20}, {\[Theta], -\[Pi], \[Pi]}, PlotPoints -> 100, PlotRange -> All,
AspectRatio -> Automatic, DisplayFunction ->
ReplaceAll[{r_Real, \[Theta]_Real} :> {r*Cos[\[Theta]], r*Sin[\[Theta]]}]]
My answer to metroidman's question contains two solutions that work. The first is essential the same as @Heike's answer here, which I had missed earlier and upvoted now, and very similar to the answer @metroidman posted. My second solution using the polarEquationPlot[]
package adaptively refines the curves in the geometry of the $xy$ plane instead of in the $\theta r$ plane (see my answer).
Get["https://raw.githubusercontent.com/mroge02/polarEquationPlot/main/polarEquationPlot.wl"]
polarEquationPlot[\[Theta]^2 == ((3 \[Pi])/4)^2 Cos[
r], {\[Theta], -2 \[Pi], 2 \[Pi]}, {r, -20, 20},
PolarGridLines -> Automatic, GridLinesStyle -> Thin]