5
$\begingroup$

I have a function $Z(r, \theta)$ that I would like to plot over the unit disk. I could of course plot it as $Z(\sqrt{x^2+y^2}, \arctan(y/x))$, but the best I can do with this is a square plot. I would like a plot defined from $0<R<1$ and $0<\theta<2\pi$, such that it looks something like the plots shown here:

Zernike polynomial plots

How can I make Mathematica generate a plot like this? Thank you!

$\endgroup$
4
  • $\begingroup$ You might be interested in RegionFunction. $\endgroup$ Nov 24, 2015 at 6:07
  • $\begingroup$ Ah that works perfectly - thank you!! Though I do wonder if Mathematica has something more intuitive built in, as it seems like a common enough application. $\endgroup$ Nov 24, 2015 at 6:10
  • $\begingroup$ Just to be clear, I'm still leaving this open for a solution as this method doesn't quite work - using $\arctan(y/x)$ causes discontinuities at x=0 that mess up the way the plot comes out. $\endgroup$ Nov 24, 2015 at 6:34
  • $\begingroup$ That's because you have to use two-argument arctangent (ArcTan[x, y]) for the purpose. $\endgroup$ Nov 24, 2015 at 6:39

1 Answer 1

8
$\begingroup$

Here's my attempt to plot the Zernike functions on the unit disk:

ZernikeZ[n_Integer, m_Integer, r_, θ_] /; -n <= m <= n := 
         If[m < 0, Sin[m θ], Cos[m θ]] ZernikeR[n, m, r]

Table[DensityPlot[ZernikeZ[n, m, Norm[{x, y}], ArcTan[x, y]], {x, y} ∈ Disk[],
                  ColorFunction -> (ColorData[{"ThermometerColors",  "Reverse"},
                                              LogisticSigmoid[2 #]] &), 
                  ColorFunctionScaling -> False, Frame -> False, 
                  PlotPoints -> 55],
      {n, 0, 4}, {m, -n, n, 2}] // GraphicsGrid

Zernike on a disk

$\endgroup$
5
  • $\begingroup$ (Older versions of Mathematica can use RegionFunction instead.) $\endgroup$ Nov 24, 2015 at 6:44
  • 1
    $\begingroup$ Much older ones ... v9 accepts Disk[ ] $\endgroup$ Nov 24, 2015 at 6:46
  • $\begingroup$ Is the LogisticSigmoid[ ] in there for pure Fermi love, or is something really useful? $\endgroup$ Nov 24, 2015 at 6:47
  • 2
    $\begingroup$ @bel, it allows me to map $(-\infty,\infty)$ to $(0,1)$, with $0$ being the white(-ish) color, and positive and negative values mapped to the extreme colors. I've used this rescaling before on this site... $\endgroup$ Nov 24, 2015 at 6:49
  • $\begingroup$ Ah, OK.nice one.Don't remember seeing it used like this before, but the German doctor is always mumbling in my ear trying to distract me, so ... $\endgroup$ Nov 24, 2015 at 6:51

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.