1

I would like to draw a circle separated in 4 part by two sin functions. And I'd like to fill each part with a different color. But I don't know how to make the area follow the sinus

enter image description here

What I've done yet:

\documentclass{standalone}

\usepackage[francais]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usetikzlibrary{shapes,snakes}
\usetikzlibrary{calc}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
    \node (m1) at (1,2.6) {};
\draw[fill=gray!50] (m1) circle (1 and 0.5);

\draw[fill=blue!40] (m1) circle (0.3);
\draw[fill=blue!70] (m1) circle (0.25);

% Horizontal sin
\draw[smooth, samples=200, domain=-0.1:2.1, color=red!70] (m1)
plot(\x, {sin(\x*10 r)*0.03+2.6});
% Vertical sin
\draw[smooth, samples=200, domain=2:3.2, color=red!70] (m1)
plot({sin(\x*10 r)*0.03+1}, \x);
\end{tikzpicture}
\end{document}
  • What packages are you using? (I think I'm missing one in my code.) – heather Aug 7 '16 at 14:37
  • I've taken the liberty to edit your MWE, so that it compiles fine for everybody. In the future, remember to add \documentclass any packages needed, \begin{document} and other code needed to run the Minimal Working Example. – Runar Aug 7 '16 at 14:41
  • I'm sorry for this. :s I edited my post – Phantom Aug 7 '16 at 14:48
  • @heather I don't think so. Code works fine without any \usetikzlibrary{}. – Runar Aug 7 '16 at 14:58
  • Which circle? All 3? – Alenanno Aug 7 '16 at 15:07
0

Clipping helps to get different colors in the four quadrants of the two circles:

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[
  smooth,
  samples=200,
]
  \coordinate (m1) at (1,2.6);
  \def\llx{-.1}
  \def\lly{2}
  \def\urx{2.1}
  \def\ury{3.2}
  \def\PlotSinV{plot[domain=\lly:\ury]({sin(\x*10 r)*0.03+1}, \x)}
  \def\PlotSinH{plot[domain=\llx:\urx] (\x, {sin(\x*10 r)*0.03 + 2.6})}

  % Large grey ellipsis
  \draw[fill=gray!50] (m1) circle (1 and 0.5);

  % Clip right half
  \begin{scope}
    \clip (m1) \PlotSinV -- (\urx, \ury) -- (\urx, \lly) -- cycle;

    % Clip upper half, intersection with right half => quadrant I
    \begin{scope}
      \clip (m1) \PlotSinH -- (\urx, \ury) -- (\llx, \ury) -- cycle;
      \draw[fill=blue!40] (m1) circle (0.3);
      \draw[fill=blue!70] (m1) circle (0.25);
    \end{scope}

    % Clip lower half => quadrant II
    \begin{scope}
      \clip(m1) \PlotSinH -- (\urx, \lly) -- (\llx, \lly) -- cycle;
      \draw[fill=orange!40] (m1) circle (0.3);
      \draw[fill=orange!70] (m1) circle (0.25);
    \end{scope}
  \end{scope}

  % Clip left half
  \begin{scope}
    \clip (m1) \PlotSinV -- (\llx, \ury) -- (\llx, \lly) -- cycle;

    % Clip lower half => quadrant III
    \begin{scope}
      \clip (m1) \PlotSinH -- (\urx, \lly) -- (\llx, \lly) -- cycle;
      \draw[fill=green!40] (m1) circle (0.3);
      \draw[fill=green!70] (m1) circle (0.25);
    \end{scope}

    % Clip upper half => quadrant IV
    \begin{scope}
      \clip (m1) \PlotSinH -- (\urx, \ury) -- (\llx, \ury) -- cycle;
      \draw[fill=magenta!40] (m1) circle (0.3);
      \draw[fill=magenta!70] (m1) circle (0.25);
    \end{scope}
  \end{scope}

  \draw[red!70] (m1) \PlotSinH (m1) \PlotSinV;
\end{tikzpicture}
\end{document}

Result

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.