4

The excellent Hobby library's documentation says that it is possible to save and reuse Hobby paths. The examples include paths which are shifted and redrawn with different properties.

However, I cannot figure out how to get my restored paths to behave properly. They seem to get lost when drawing the start or end of the path and to end up in the wrong place.

As I understand it, the red, blue and grey curves should all be identical, with the blue and grey shifted slightly to the left and right of the original red. However, neither the blue nor grey is the same shape as the red, as I believe they should be.

What am I doing wrong?

\documentclass[tikz,12pt]{standalone}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}
  \path [draw=red] (0,0) coordinate (f) to[curve through={+(.125,-.5) +(-.5,-1) +(0,-1.5) +(.5,-.75) }, save Hobby path={ff1}] (f);
  \path [draw=blue,xshift=1mm] (f) [restore and use Hobby path={ff1}{}];
  \path [draw=gray,xshift=-1.5mm] (f) [restore and use Hobby path={ff1}{}];
\end{tikzpicture}
\end{document}

wayward Hobby paths

  • The (already defined) position of the f coordinate is not modified by the xshift operation. – Paul Gaborit May 5 '17 at 6:50
  • BTW: how did you obtain such smooth lines in your question? The picture from my answer has 600 or 1200 dpi resolution (PNG) and is of much worse quality. – Przemysław Scherwentke May 7 '17 at 11:57
  • @PrzemysławScherwentke It is just how they come out. I just clip them in Okular. – cfr May 7 '17 at 22:31
7

Replacing the absolute (f) by the relative (0,0) gives the desired result (here also with the variant using scope):

\documentclass[tikz,12pt]{standalone}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}
%  \path [draw=red] (0,0) coordinate (f) to[curve through={+(.125,-.5) +(-.5,-1) +(0,-1.5) +(.5,-.75) }, save Hobby path={ff1}] (f);
\path [draw=red] (0,0) coordinate (f) to[curve through={+(.125,-.5) +(-.5,-1) +(0,-1.5) +(.5,-.75) }, save Hobby path={ff1}] (f);
\begin{scope}[xshift=+1mm]
%  \path [draw=blue,xshift=1mm] (f) [restore and use Hobby path={ff1}{}];
 \path [draw=blue] (0,0) [restore and use Hobby path={ff1}{}];
 \end{scope} 
  \path [draw=gray,xshift=-1.5mm] (0,0) [restore and use Hobby path={ff1}{}];
\end{tikzpicture}
\end{document}

enter image description here

3

Just for comparison of the syntax, here's the same diagram written in Hobby's own Metapost...

\RequirePackage{luatex85}
\documentclass[border=10bp]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
  path ff;
  ff = ((0,0) .. (1/8,-1/2) .. (-1/2,-1) .. 
     (0,-3/2) .. (1/2,-3/4) .. (0,0) .. cycle) scaled 28;
  draw ff withcolor red;
  draw ff shifted 3 right withcolor blue;
  draw ff shifted 5 left  withcolor 1/2 white;
endfig;
\end{mplibcode}
\end{document}

enter image description here

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.