3

Suppose one wants to achieve the following: Goal: Two pathmorphing/pathreplacing decorations in succession

Current Status

Based upon another post, I was able to create a "MWE" of how I would like this to work:

\documentclass[border=5pt]{standalone}

\usepackage{tikz} \usetikzlibrary{decorations, decorations.pathmorphing, decorations.pathreplacing}

\def\width{5mm}

\pgfdeclaredecoration{make wide}{initial} { \state{initial}[width=1pt] { \pgfpathmoveto{\pgfpoint{0pt}{-0.5\width}} \pgfpathlineto{\pgfpoint{1pt}{-0.5\width}} \pgfpathmoveto{\pgfpoint{0pt}{0.5\width}} \pgfpathlineto{\pgfpoint{1pt}{0.5\width}} } \state{final} { \pgfpathmoveto{\pgfpoint{0pt}{0.5\width}} \pgfpathlineto{\pgfpoint{1pt}{0.5\width}} \pgfpathmoveto{\pgfpoint{0pt}{-0.5\width}} \pgfpathlineto{\pgfpoint{1pt}{-0.5\width}} } }

\tikzstyle{make wide and ticks} = [ decoration={make wide}, decorate, postaction={ decoration={ticks}, decorate } ]

\begin{document} \begin{tikzpicture} \drawmake wide and tickstoout=0, in=180; \end{tikzpicture} \end{document}

However, the output is:
MWE: Resulting Output

To rule out any weird order of execution issues that I previously encountered with tikzstyle, I also tried it without defining a tikzstyle with the same result (just like one would expect). From my understanding of the implementation of postaction, it is not possible to to use every decoration within the postaction phase.

Questions:

  1. Is there a way to achieve the desired output with decorations?
  2. Is there another simple way that also works for arbitrary shaped paths?
dsacre
  • 327
  • 1
  • 7

1 Answers1

3

enter image description here

The solution is realized in two steps:

  1. points characterizing a certain tubular neighborhood of the path are constructed through a decoration towards tubular which takes two arguments (step and distance from the path that are taken in pt)
  2. the two corresponding paths of the tubular neighborhood are constructed and decorated with the predefined decoration ticks through the commands L ticks and R ticks (left and right tubular borders).

Note, in the first drawing of the above figure, that there is a problem with the last tick of the decoration; it does not "cover" the last part of the initial path (drawn in black). For this reason, some "tail" is added and then the decoration towards tubular is invoked (see the middle drawing). The tail is added through the option e.

I hope that the last drawing approaches what you are looking for.

The code

\documentclass[11pt, margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{math}
\usetikzlibrary{decorations.markings, decorations.pathreplacing}

\begin{document} \tikzset{% e/.style={% step length -- in points % needed for the last tick of open curves insert path={-- ([turn]0: #1pt)} }, towards tubular/.style 2 args={% step length, width -- in points % create the points describing the tubular neighborhood decoration={markings, mark=between positions 0 and 1 step #1pt with { \tikzmath{% integer \pNumber; \pNumber = \pgfkeysvalueof{/pgf/decoration/mark info/sequence number}; } \pgfextra{\xdef\pNumber{\pNumber}} \path (0, #2pt) coordinate (TL-\pNumber); \path (0, -#2pt) coordinate (TR-\pNumber); } }, postaction=decorate }, L ticks/.style 2 args={% step length, tick length -- in points decorate, decoration={ticks, segment length=#1pt, amplitude=#2pt}, insert path={% (TL-1) \foreach \i in {2, ..., \pNumber}{-- (TL-\i)} } }, R ticks/.style 2 args={% step length, tick length -- in points decorate, decoration={ticks, segment length=#1pt, amplitude=#2pt}, insert path={% (TR-1) \foreach \i in {2, ..., \pNumber}{-- (TR-\i)} } } }

\begin{tikzpicture} \draw[help lines, opacity=.3] (-4, -3) grid (4, 4);

% first drawing \draw[towards tubular={3}{6}] (-3, -2.5) .. controls ++(30:5) and ++(210:3) .. ++(-1, 6); \draw[blue, L ticks={4}{2}]; \draw[red, R ticks={4}{2}];

% second drawing \path[towards tubular={6}{6}] (0, -2.5) .. controls ++(30:5) and ++(210:3) .. ++(-1, 6) [e=5]; \draw (0, -2.5) .. controls ++(30:5) and ++(210:3) .. ++(-1, 6); \draw[blue, L ticks={4}{2}]; \draw[red, R ticks={4}{2}];

% third drawing \path[towards tubular={3}{6}] (3, -2.5) .. controls ++(30:5) and ++(210:3) .. ++(-1, 6) [e=3]; \draw[blue, L ticks={4}{2}]; \draw[red, R ticks={4}{2}]; \end{tikzpicture} \end{document}

Daniel N
  • 5,687
  • Thank you very much! This solution does almost what I need; I can easily adapt it to my case specific needs. As an added bonus, your suggestion contains an interesting approach using e/.style to fix path length issues, which I had also some struggles with and now was answered before even asking :-) – dsacre Mar 22 '24 at 09:29