2

Update

How can I get the shade to vary in the theta direction of the transformed figure rather than left to right? I was hoping the left to right shading in the original rectangle would become a shading in the increasing theta direction! enter image description here

\documentclass{standalone}
\usepackage{tikz}
\usepgfmodule{nonlineartransformations}
\usepgfmodule[nonlineartransformations]

\makeatletter
\def\polartransformation
{
    % \pgf@x will contain the radius
    % \pgf@y will contain the distance
    \pgfmathsincos@{\pgf@sys@tonumber\pgf@x}%
    % pgfmathresultx is now the cosine of radius and
    % pgfmathresulty is the sine of radius
    \pgf@x=\pgfmathresultx\pgf@y%
    \pgf@y=\pgfmathresulty\pgf@y%
}
\makeatother

\begin{document}
    \begin{tikzpicture}

    \draw [black, left color=white, right color=gray ] (3,1) rectangle (7.5,2);
    {
        \pgftransformnonlinear{\polartransformation}
        \pgfsettransformnonlinearflatness{2pt}
        \draw [black, left color=white, right color=gray ] (3,1) rectangle (7.5,2);
    }
    \end{tikzpicture}
\end{document}

Original Problem:

I simply wish to transform this shaded region into an annular one using a polar coordinated transformation. The resulting shaded region should be an annular slice illustrated in the simple diagram (sorry for poor quality). I want the shading to maintain its "orientation". The rectangle is created in the tikz code below with most code taken from the PGF manual.

enter image description here

\documentclass{standalone}
\usepackage{tikz}
\usepgfmodule{nonlineartransformations}
\usepgfmodule[nonlineartransformations]

\def\polartransformation
{
    % \pgf@x will contain the radius
    % \pgf@y will contain the distance
    \pgfmathsincos@{\pgf@sys@tonumber\pgf@x}%
    % pgfmathresultx is now the cosine of radius and
    % pgfmathresulty is the sine of radius
    \pgf@x=\pgfmathresultx\pgf@y%
    \pgf@y=\pgfmathresulty\pgf@y%
}


\begin{document}
    \begin{tikzpicture}

    \draw[black] (0:20mm) arc [start angle=0,end angle = 90, radius=2cm];
    {
        \pgftransformnonlinear{\polartransformation}
        \pgfsettransformnonlinearflatness{2pt}
        \draw [black, left color=white, right color=gray ] (3,3) rectangle (4,3.5);
    }
    \end{tikzpicture}
\end{document}

But here I get the error:

Missing number, treated as zero. ...left color=white, right color=gray ] (3,3)
  • This is given in the manual with polartransformation in the nonlinear transformations section – percusse Nov 10 '17 at 20:56
  • OK I will check that - so basically I should be able to define my rectangle in a scope and then apply the transformation to it? – Dipole Nov 10 '17 at 21:09
  • @Cragfelt I think the link may be wrong? – Dipole Nov 11 '17 at 15:01
  • You need to add \makeatletterbefore the definition and \makeatother after the definition of polartransformation to make it work since the macros involve @ character – percusse Nov 11 '17 at 15:14
  • 1
    I updated my question to focus on the shading part now that I can do the transformation – Dipole Nov 11 '17 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.