5

I am currently trying to do some decoration on a path built from a list of coordinates and cycle. I observe a weird result at the closing point of the cycle. I am looking for a solution to remove it.

MWE

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees,decorations}
\begin{document}
\begin{tikzpicture}[]
\coordinate (K) at (3,1);
\coordinate (of) at (7,1.5);
%\draw[help lines] (0,0) grid (10,5);
\draw[decorate,black,decoration={curveto,raise=-10pt}] (K) plot [smooth cycle,tension=0.7] coordinates {(3,1) (5,1.2) (7,1) (8,3) (7,4.5) (5,4.5) (2,4) (1.7,2.5)};
\draw[black] (K) plot [smooth cycle,tension=0.7] coordinates {(3,1) (5,1.2) (7,1) (8,3) (7,4.5) (5,4.5) (2,4) (1.7,2.5)};
\end{tikzpicture}
\end{document}

Bad paths

3
\documentclass[border=9,tikz]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\makeatletter

\pgfdeclaredecoration{raise close}{start}{
    \state{start}[width=+0pt,next state=iterate,persistent precomputation=\pgfdecoratepathhascornerstrue]
        {\pgfpathmoveto{\pgfpoint{0pt}{\pgfdecorationsegmentamplitude}}}
    \state{iterate}[width=+\pgfdecorationsegmentlength]{\pgfpathlineto{\pgfpoint{0pt}{\pgfdecorationsegmentamplitude}}}
    \state{final}{\pgfpathclose}
}
\pgfdeclaredecoration{raise open}{start}{
    \state{start}[width=+0pt,next state=iterate,persistent precomputation=\pgfdecoratepathhascornerstrue]
        {\pgfpathmoveto{\pgfpoint{0pt}{\pgfdecorationsegmentamplitude}}}
    \state{iterate}[width=+\pgfdecorationsegmentlength]{\pgfpathlineto{\pgfpoint{0pt}{\pgfdecorationsegmentamplitude}}}
    \state{final}{}
}
\tikz{
    \draw[decorate,decoration={raise close,amplitude=-10pt,segment length=1pt}]
          plot[smooth cycle,tension=.7]coordinates{(3,1)(5,1.2)(7,1)(8,3)(7,4.5)(5,4.5)(2,4)(1.7,2.5)};
    \draw plot[smooth cycle,tension=.7]coordinates{(3,1)(5,1.2)(7,1)(8,3)(7,4.5)(5,4.5)(2,4)(1.7,2.5)};
}

\tikz{
    \draw[double,double distance=10pt]
          plot[smooth cycle,tension=.7]coordinates{(3,1)(5,1.2)(7,1)(8,3)(7,4.5)(5,4.5)(2,4)(1.7,2.5)};
}

\end{document}

Perhaps add these lines before your picture. \makeatletter \pgfutil@namedef{pgf@decorate@@curveto@initial}{safeinit} \pgfutil@namedef{pgf@decorate@@curveto@safeinit@options}{next state=initial,width=1pt} \pgfutil@namedef{pgf@decorate@@curveto@safeinit@code}{\pgfpathmoveto{\pgfpointorigin}} \pgfutil@namedef{pgf@decorate@@curveto@final@code}{\pgfpathclose} \makeatother
  • Thank you. It works in my case but it seems to not work in all cases (it damages other kind of decoration not presented here). – Guuk May 31 '18 at 15:29
  • @Guuk Sorry I was not aware of how general this question could be. In general you can look at pgfmoduledecorations.code.tex line 2138-2144. It tells you how curveto is defined. And you can make your own definition. – Symbol 1 May 31 '18 at 18:24
  • Yes I know. I just put this comment to precise some limits of your first proposition. Thank you for the second one. – Guuk May 31 '18 at 18:49

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.