3

I struggle to make a radial shading on a portion of a disk (resembling a pizza slice), and I wonder if someone could help me with that!

Basically I have the figure produced by that code:

\begin{tikzpicture}[scale=1]
\pgfmathsetmacro{\cos}{0.5}
\pgfmathsetmacro{\sin}{sqrt(3)/2}
\pgfmathsetmacro{\size}{6}
\pgfmathsetmacro{\pis}{30}
\pgfmathsetmacro{\sizecore}{1.2}
\pgfmathsetmacro{\sizeDDcore}{1.2}
\pgfmathsetmacro{\sizeDDHe}{1}
\pgfmathsetmacro{\begDDHe}{4.2}
\pgfmathsetmacro{\sizeDDHe}{0.6}
\pgfmathsetmacro{\endDDHe}{\begDDHe+\sizeDDHe}
%   
%% Main shape (pizza share like)
\draw[thick, color=gray!50] (0,0) -- (\size*\cos,\size*\sin);
\draw[thick, color=gray!50] (0,0) -- (-\size*\cos,\size*\sin);
\draw[thick, color=gray!50] (\size*\cos, \size*\sin) arc (60: 120: \size);
\fill[orange!40] (0,0) -- (\size*\cos,\size*\sin) arc (60: 120: \size) -- (-\size*\cos,\size*\sin) -- cycle;
\fill[orange!60] (0,0) -- (\begDDHe*\cos,\begDDHe*\sin) arc (60: 120: \begDDHe) -- (-\begDDHe*\cos,\begDDHe*\sin) -- cycle;
%% Core
\fill[fill=red!80] (0,0) -- (\sizecore*\cos,\sizecore*\sin) arc (60:120:\sizecore) -- (-\sizecore*\cos,\sizecore*\sin) -- cycle;
%% DD region just outside the core
\fill[fill=red!50]
    (-\sizecore*\cos,\sizecore*\sin) arc (120:60:\sizecore) -- (\sizecore*\cos,\sizecore*\sin) -- (\sizecore*\cos+\sizeDDcore*\cos,\sizecore*\sin+\sizeDDcore*\sin) arc (60:120:\sizecore+\sizeDDcore) -- (-\sizecore*\cos-\sizeDDcore*\cos,\sizecore*\sin+\sizeDDcore*\sin) -- cycle;
%% DD in the He region
\fill[fill=blue!50] (-\begDDHe*\cos,\begDDHe*\sin) arc (120:60:\begDDHe) -- (\begDDHe*\cos,\begDDHe*\sin) -- (\endDDHe*\cos,\endDDHe*\sin) arc (60:120:\endDDHe) -- (-\endDDHe*\cos,\endDDHe*\sin) -- cycle;

with result:

enter image description here

and I would like to have a radial shading to match regions with different colors smoothly.

Thanks in advance for your help !

Cheers, Quentin

  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – samcarter_is_at_topanswers.xyz Nov 21 '16 at 15:43
  • If you search here for "radial shanding" you will find several examples (such as tex.stackexchange.com/questions/141339/…) – John Kormylo Nov 22 '16 at 4:38
3

First I feel compelled to note that your original code could be made much simpler by using polar coordinates (and a foreach loop):

\begin{tikzpicture}[scale=6]
\foreach \x/\c in {1/orange!40, .8/blue!50, .7/orange!60, .4/red!50, .2/red!80}{
  \fill[\c] (0,0) -- +(60:\x) arc (60:120:\x);
}
\draw[thick, gray!50] (0,0) -- +(60:1) arc (60:120:1) --cycle;
\end{tikzpicture}

But since you asked for a radial shading, here you go:

\documentclass[tikz, border=5pt]{standalone}
\pgfdeclareradialshading{pizza}{\pgfpointorigin}{%
  color(0cm)=(red!80);
  color(1.1cm)=(red!80);
  color(1.3cm)=(red!50);
  color(2.3cm)=(red!50);
  color(2.5cm)=(orange!60);
  color(4.1cm)=(orange!60);
  color(4.3cm)=(blue!50);
  color(4.7cm)=(blue!50);
  color(4.9cm)=(orange!40);
  color(6.0cm)=(orange!40)
}
\begin{document}
\begin{tikzpicture}
  \begin{scope}
    \clip (0,0) -- +(60:6) arc (60:120:6) --cycle;
    \pgfuseshading{pizza}
  \end{scope}
  \draw[thick, gray!50] (0,0) -- +(60:6) arc (60:120:6) --cycle;
\end{tikzpicture}
\end{document}

shaded sector

(I think I'm missing your color definitions, so my colors do not match yours.) Note that shading may be poorly rendered by some pdf viewers.

Or, for a more scalable solution, you could use

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\pgfdeclareradialshading{pizza}{\pgfpointorigin}%
{color(0cm)=(red!80);
color(.16cm)=(red!80);
color(.19cm)=(red!50);
color(.34cm)=(red!50);
color(.37cm)=(orange!60);
color(.61cm)=(orange!60);
color(.64cm)=(blue!50);
color(.70cm)=(blue!50);
color(.73cm)=(orange!40);
color(.9cm)=(orange!40)
}
\begin{document}
\begin{tikzpicture}
  \begin{scope}
    \clip (0,0) -- +(120:6) arc (120:60:6) --cycle;
    \shade[shading=pizza] (0,0) circle (6);
  \end{scope}
  \draw[thick, gray!50] (0,0) -- +(60:6) arc (60:120:6) --cycle;
\end{tikzpicture}
\end{document}

In this version the shading will scale with the radius of the circle. For some reason the outside of the circle is at about .88cm in the shading specification (I've rounded up to .9). If anyone knows the origin (or a more precise value) of this number I'd love to hear it.

| improve this answer | |

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.