我正在尝试绘制一个三线网络(用三种不同的颜色表示),如下所示。
这是我的 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,blue]{G-\i}{{(\i)*\pairdist-\wiredist},0}{\wireheight}{-\wirewidth}
\wire[thick,blue]{B-\i}{\i*\pairdist,0}{\wireheight}{\wirewidth}
\wire[thick,blue]{B-\i}{\i*\pairdist,1}{\wireheight}{\wirewidth}
}
\draw[<->] ($(G-1-2)!0.5!(G-1-3)$) -- +(-0.5,0) node[midway,above]{$\theta_{2}$};
\draw[<->] ($(G-1-2)!-0.5!(G-2-3)$) -- +(-0.5,0) node[midway, above]{$\theta_{1}$};
\end{tikzpicture}
\end{document}
答案1
希望这就是你的想法
\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
\newcommand\fwidth{0.7} % for the black wire
\pgfmathsetmacro\blockwidth{2 * \wirewidth + \fwidth * \wirewidth + 3 * \wiredist} % block size
\newcommand\mup[1]{-- ++ (90 : #1 * \wireheight)}
\newcommand\mright[1]{-- ++ (0 : #1 * \wirewidth)}
\newcommand\mleft[1]{-- ++ (180 : #1 * \wirewidth)}
% \wire[options]{name}{start}{width}
\newcommand\gwire[4][]{
\draw[#1] (#3, 0) \mup{1} \mright{#4} \mup{1} \mleft{#4} \mup{2} \mright{#4} \mup{1} \mleft{#4} \mup{1} \mright{#4} \mup{1} coordinate (#2-1);
}
\newcommand\kwire[4][]{
\draw[#1] (#3, 0) ++ (#4, 0) \mup{1} \mleft{#4} \mup{1.3} \mright{#4} \mup{1.7} \mleft{#4} \mup{1.2} \mright{#4} \mup{1.8} coordinate (#2-1);
}
\newcommand\bwire[4][]{
\draw[#1] (#3, 0) \mup{2} \mright{#4} \mup{1} \mleft{#4} \mup{2} \mright{#4} \mup{1} \mleft{#4} \mup{1} coordinate (#2-1);
}
\begin{document}
\begin{tikzpicture}[rounded corners,>=stealth, shorten >=1pt, shorten <=1pt]
\foreach \i in {0,...,2}
{
\gwire[thick,green]{G-\i}{\i * \blockwidth}{1}
\kwire[thick,black]{K-\i}{\i * \blockwidth + \wirewidth + \wiredist}{\fwidth}
\bwire[thick,blue]{B-\i}{\i * \blockwidth + \wirewidth + \fwidth * \wirewidth + 2 * \wiredist}{1}
}
\draw[<->] (K-0-1) -- (B-0-1) node[above, midway]{$\theta_1$};
\end{tikzpicture}
\end{document}