3

I want to draw an arbitrary domain which I can split in two along an arbitrary curve so I can colour both subdomains using different colours. I tried drawing the domain using the hobby library, however I don't know how to colour it separately. I attach the code of what I tried below.

\documentclass[tikz]{standalone}
\usetikzlibrary{hobby}

\begin{document}
\begin{tikzpicture}[use Hobby shortcut,closed=true]
  \fill[draw=black, fill=orange] (-3.5,0.5) .. (-3,2.5) .. (-1,3.5).. (1.5,3).. (4,2.5).. (5,0.5) ..(2.5,-2).. (0,-1.5).. (-2.5,-2).. (-3.5,0.5);
  \draw[black] (-3.5, 0.5) to [out=0, in=-135] (-1.5,1) to[out=45, in=-118] (1.5,0) to[out=62, in=150] (5,0.5);
  \node[above] at (0,1.5) {Colour A};
  \node[above] at (0, -1) {Colour B};
\end{tikzpicture}
\end{document}

Thank you very much!

4

For example, clipping can be used without the need to modify the curves:

\documentclass[tikz]{standalone}
\usetikzlibrary{hobby}

\begin{document}
\begin{tikzpicture}[use Hobby shortcut,closed=true]
  %\fill[draw=black, fill=orange]
  \def\OuterCurve{%
    (-3.5,0.5) .. (-3,2.5) .. (-1,3.5) .. (1.5,3) .. (4,2.5) ..
    (5,0.5) ..(2.5,-2).. (0,-1.5).. (-2.5,-2).. (-3.5,0.5)
  }
  \coordinate (Left) at (-3.5, 0.5);
  \coordinate (Right) at (5, 0.5);
  \def\InnerCurve{%
    (Left) to [out=0, in=-135] (-1.5,1) to[out=45, in=-118]
    (1.5,0) to[out=62, in=150] (Right)
  }

  % Fill areas
  \begin{scope}
    \clip[use Hobby shortcut, closed=true] \OuterCurve;
    \begin{scope}
      \clip \InnerCurve
        -- (current bounding box.east |- Right)
        -- (current bounding box.south east)
        -- (current bounding box.south west)
        -- (current bounding box.west |- Left)
        -- cycle
      ;
      \fill[green] (current bounding box.south west)
        rectangle (current bounding box.north east)
      ;
    \end{scope}
    \clip \InnerCurve
      -- (current bounding box.east |- Right)
      -- (current bounding box.north east)
      -- (current bounding box.north west)
      -- (current bounding box.west |- Left)
      -- cycle
    ;
    \fill[orange] (current bounding box.south west)
      rectangle (current bounding box.north east)
    ;
  \end{scope}

  % Draw black curves
  \draw[use Hobby shortcut, closed=true] \OuterCurve;
  \draw \InnerCurve;

  \node[above] at (0,1.5) {Colour A};
  \node[above] at (0, -1) {Colour B};
\end{tikzpicture}
\end{document}

Result

Remark:

  • The clipping is additive, further \clip commands in the same scope reduce the clipped area by intersecting the current clipping path with the new path.

  • The scope of the clipping can be controlled by environment scope. The \end{scope} restores the previous clipping path.

  • Thank you very much! On another topic, how do you manage to embed the image generated by your code in the post? – Ferran Brosa Planella May 12 '16 at 7:26
  • @FerranBrosaPlanella In short: \pagestyle{empty} + pdflatex + pdfcrop + Ghostscript (device=pngalph). Then embedded as quotation. – Heiko Oberdiek May 12 '16 at 17:10

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.