[Tex/LaTex] Fill in between polar curves

fillbetweenpolarplottikz-pgf

I am trying to fill in space between a pair of spiral curves in tikz. I have tried using the fillbetween library but it just shades in the whole spiral. Does anyone have a hint they could offer? Thanks.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usepgfplotslibrary{polar}  
\begin{document}
\begin{tikzpicture}[scale=0.5]
   \begin{polaraxis}[hide axis]
    \addplot [mark=none,domain=0:720,samples=600,thick,gray] {0.5*x};
    \addplot [mark=none,domain=0:720-180,samples=600,thick,gray] {-0.667*x};    

    %\addplot [mark=none,domain=0:720,samples=600,thick,gray] {-0.5*x};     
    %\addplot [mark=none,domain=0:720-180,samples=600,thick,gray] {0.667*x}; 

    \end{polaraxis}
\end{tikzpicture}
\end{document}

Best Answer

In the meantime, here is a solution with MetaPost. Since the syntax of Tikz and MetaPost have many similarities, it may help to provide the desired solution.

The key point is to append the two spirals (one of them reverted), close the resulting path (--cycle instruction) and then fill it:

fill spiral1--reverse spiral2--cycle withcolor .8white;

I have inserted the MetaPost code into a LuaLaTeX program for typesetting convenience:

\documentclass[border=2mm]{standalone}
\usepackage{luamplib}
  \mplibsetformat{metafun}
\begin{document}
  \begin{mplibcode}
    vardef polarfcn(expr tmin, tmax, tstep)(text f_t) =
      save t; t := tmin;
      (f_t*cos t, f_t*sin t)
      forever: hide(t := t + tstep) exitunless t <= tmax;
        .. (f_t*cos t, f_t*sin t)
      endfor
      if t - tstep < tmax: hide(t := tmax) .. (f_t*cos t, f_t*sin t) fi
    enddef;
    u := cm;
    beginfig(1);
      path spiral[]; 
      spiral1 = polarfcn(0, 4pi, 4pi/600)(.5t) scaled u;
      spiral2 = polarfcn(0, 3pi, 3pi/600)(-2/3t) scaled u;
      fill spiral1--reverse spiral2--cycle withcolor .8white;
      draw spiral1; draw spiral2;
    endfig; 
  \end{mplibcode}
\end{document}

Output:

enter image description here

Edit Here is a variant (with the same output), inspired by Thruston's remark.

\documentclass[border=2mm]{standalone}
\usepackage{luamplib}
\begin{document}
  \begin{mplibcode}
    vardef polarpnt(expr r, t) = r*dir t enddef;
    vardef polarfcn(expr tmin, tmax, tstep)(text r) =
      save t; t := tmin;
      polarpnt(r, t)
      forever: hide(t := t + tstep) exitif t > tmax; .. polarpnt(r, t) endfor
      if t - tstep < tmax: hide(t := tmax) .. polarpnt(r, t) fi
    enddef;
    beginfig(1);
      path spiral[]; 
      spiral1 = polarfcn(0, 720, 1)(.5t);
      spiral2 = polarfcn(0, 540, 1)(-2/3t);
      fill spiral1 .. reverse spiral2 .. cycle withcolor .8white;
      draw spiral1; draw spiral2;
    endfig; 
  \end{mplibcode}
\end{document}