11

I'm afraid that I have a followup question to this one.

Consider the following MWE

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
  \begin{tikzpicture}[scale=.25]
    \tikzset{
      ncbar/.style={
        to path=%
        ($(\tikztostart)!#1!90:(\tikztotarget)$)
        -- ($(\tikztotarget)!($(\tikztostart)!#1!90:(\tikztotarget)$)!90:(\tikztostart)$)
      },
      ncbar/.default=0.5cm,
    }

    \draw[red,ultra thin] (0,0) -- (1,2) -- (2,0);
    \draw[blue,ultra thin] (0,0) to[ncbar=0.25cm] (1,2) to[ncbar=0.25cm] (2,0);

  \end{tikzpicture}
\end{document}

which yields: enter image description here

Note that the source of the second part of the blue path is not "correct". In turn, the second blue part is not parallel to the red counterpart. How can I fix this? Somehow reset/set \tikztostart?

Bonus question: How can I bridge the gap between the two blue parts using the missing part of a circle arc (this circle centered at the apex of the red curve and of radius 0.25cm in this example)?

Dror
  • 22,613

1 Answers1

11

You have to include the final (\tikztotarget) in the to path definition (without the preceding --):

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
  \begin{tikzpicture}[scale=.25]
\tikzset{
    ncbar angle/.initial=90,
    ncbar/.style={
        to path=($(\tikztostart)!#1!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztotarget)$)
        -- ($(\tikztotarget)!($(\tikztostart)!#1!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztotarget)$)!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztostart)$)
        (\tikztotarget)
    },
    ncbar/.default=0.5cm,
}

    \draw[red,ultra thin] (0,0) -- (1,2) -- (2,0);
    \draw[blue,ultra thin] (0,0) to[ncbar=0.25cm] (1,2) to[ncbar=0.25cm] (2,0);

  \end{tikzpicture}
\end{document}
Jake
  • 232,450
  • 2
    Worked like a charm. I'll wait to see if someone will add something regarding the bonus part :) – Dror Jun 05 '13 at 11:59