我有一个如下所示的图形,我想在红色和蓝色曲线之间添加一条绿色直线,但不在蓝色和红色之间添加(如果我们从左到右方向看)
这是我的 MWE,给出了上面的数字,
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand\wireheight{2} % height of one segment
\newcommand\wirewidth{1} % width of a segment
\newcommand\wiredist{0.5} % distance between wires
\pgfmathsetmacro\pairdist{2*(\wirewidth+\wiredist)} % distance between pairs of wires
% \wire[options]{name}{start}{height}{width}
\newcommand\wire[5][]%
{\draw[#1]
(#3) coordinate (#2-0)
-- ++(0,#4) coordinate (#2-1)
-- ++(#5,0) coordinate (#2-2)
-- ++(0,#4) coordinate (#2-3)
-- ++(-#5,0) coordinate (#2-4)
-- ++(0,#4) coordinate (#2-5)
-- ++(#5,0) coordinate (#2-6)
-- ++(0,0.5*#4) coordinate (#2-7);
}
\begin{document}
\begin{tikzpicture}[rounded corners,>=stealth, shorten >=1pt, shorten <=1pt]
\foreach \i in {0,...,2}
{
\wire[thick,red]{G-\i}{{(\i)*\pairdist-\wiredist},0}{\wireheight}{-\wirewidth}
\wire[thick,blue]{B-\i}{\i*\pairdist,0}{\wireheight}{\wirewidth}
}
\end{tikzpicture}
\end{document}
答案1
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand\wireheight{2} % height of one segment
\newcommand\wirewidth{1} % width of a segment
\newcommand\wiredist{0.5} % distance between wires
\pgfmathsetmacro\pairdist{2*(\wirewidth+\wiredist)} % distance between pairs of wires
% \wire[options]{name}{start}{height}{width}
\newcommand\wire[5][]%
{\draw[#1]
(#3) coordinate (#2-0)
-- ++(0,#4) coordinate (#2-1)
-- ++(#5,0) coordinate (#2-2)
-- ++(0,#4) coordinate (#2-3)
-- ++(-#5,0) coordinate (#2-4)
-- ++(0,#4) coordinate (#2-5)
-- ++(#5,0) coordinate (#2-6)
-- ++(0,0.5*#4) coordinate (#2-7);
}
\begin{document}
\begin{tikzpicture}[rounded corners,>=stealth, shorten >=1pt, shorten <=1pt]
\foreach \i in {0,...,2}
{
\wire[thick,red]{R-\i}{{(\i)*\pairdist-\wiredist},0}{\wireheight}{-\wirewidth}
\wire[thick,blue]{B-\i}{\i*\pairdist,0}{\wireheight}{\wirewidth}
\wire[thick,green]{G-\i}{{\i*\pairdist-0.5*\wiredist},0}{\wireheight}{0}
}
\end{tikzpicture}
\end{document}