It turns out some of the work is already done, but an important macro \pgfdecoratedangletonextinputsegment
is undocumented (and incorrectly defined - possibly why it is undocumented). Here's a not-very-well tested solution for straight lines only with no mid-path moveto
commands. I think dealing with curveto
and closepath
segments will also prove extra-tricky.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations}
\def\pgfdecoratedcontourdistance{0pt}
\pgfkeys{/pgf/decoration/contour distance/.code={%
\pgfmathparse{#1}%
\let\pgfdecoratedcontourdistance=\pgfmathresult}%
}
\pgfdeclaredecoration{contour lineto}{start}
{
\state{start}[next state=draw, width=0pt]{
\pgfpathmoveto{\pgfpoint{0pt}{\pgfdecoratedcontourdistance}}%
}
\state{draw}[next state=draw, width=\pgfdecoratedinputsegmentlength]{
\pgfmathparse{-\pgfdecoratedcontourdistance*cot(-\pgfdecoratedangletonextinputsegment/2+90)}%
\let\shorten=\pgfmathresult%
\pgfpathlineto{\pgfpoint{\pgfdecoratedinputsegmentlength+\shorten}{\pgfdecoratedcontourdistance}}%
}
\state{final}{
\pgfpathlineto{\pgfpoint{\pgfdecoratedinputsegmentlength}{\pgfdecoratedcontourdistance}}%
}
}
\begin{document}
\begin{tikzpicture}
\draw [
postaction={
decoration={contour lineto, contour distance=-5pt},
draw=red, dotted, decorate},
postaction={
decoration={contour lineto, contour distance=15pt},
draw=blue, dashed, decorate},
postaction={
decoration={contour lineto, contour distance=10pt},
draw=green, decorate}
]
(0, 0) -- (3, 1) -- (4, 4) -- (6, 4) --
(8,-1) -- (2,-2) -- (5, 2) -- (6, 0);
\end{tikzpicture}
\end{document}
-h*cot(A/2)
(A
is the angle between segments,h
is the outset distance).