請看下面這段程式碼
%%%%%%%%%%%%%%%%%%% MOBILE TOWER %%%%%%%%%%%%%%%%%%%%%
\newcommand{\MBS}[1]{%
\begin{tikzpicture}[]
\node[station] (base) {#1};
%\draw[line join=bevel] (base.110) -- (base.70) -- (base.north west) -- (base.north east) -- cycle;
\draw[line join=bevel] (base.100) -- (base.80) -- (base.110) -- (base.70) -- (base.north west) -- (base.north east);
\draw[line join=bevel] (base.100) -- (base.70) (base.110) -- (base.north east);
% original yshift=.8pt
%\draw[line cap=rect] ([xshift=.5cm,yshift=.3pt] base.north) [antenna=1];
%\draw[line cap=rect] ([yshift=.3pt]ant1 |- base.north) -- node[above,shape=rectangle,inner ysep=+.3333em]{\dots} ([xshift=-.5cm,yshift=.3pt]base.north) [antenna=2];
\draw[line cap=rect] ([xshift=-.1768cm,yshift=.6pt]base.north -| base.right tail) [antenna=1];
\draw[line cap=rect] ([yshift=.6pt]ant1 |- base.north) -- node[above,shape=rectangle,inner ysep=+.3333em]{\dots} ([xshift=.1768cm,yshift=.6pt]base.north -| base.left tail) [antenna=2];
%\draw[line cap=rect] ([yshift=.3pt]ant1 |- base.north) -- ([xshift=-.5cm,yshift=.3pt]base.north) [antenna=2];
%\node at ($(ant1)!0.5!(ant2)$) {\dots};
\end{tikzpicture}
}
它允許我編寫類似的命令
\draw (-4,0) node[scale=2]{\MBS{a}} ;
並產生一個中心帶有標籤“a”的圖形(在無線通訊中,該圖有點指移動塔)。現在下面的程式碼
%%%%%%%%%%%%%%%%%%%%%% RELAY %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{radiation/.style={{decorate,decoration={expanding waves,angle=90,segment length=4pt}}},
relay/.pic={
code={\tikzset{scale=5/10}
\draw[semithick] (0,0) -- (1,4);% left line
\draw[semithick] (3,0) -- (2,4);% right line
\draw[semithick] (0,0) arc (180:0:1.5 and -0.5);
\node[inner sep=4pt] (circ) at (1.5,5.5) {};
\draw[semithick] (1.5,5.5) circle(8pt);
\draw[semithick] (1.5,5.5cm-8pt) -- (1.5,4);
\draw[semithick] (1.5,4) ellipse (0.5 and 0.166);
\draw[semithick,radiation,decoration={angle=45}] (1.5cm+8pt,5.5) -- +(0:2);
\draw[semithick,radiation,decoration={angle=45}] (1.5cm-8pt,5.5) -- +(180:2);
}}
}
允許我編寫類似的程式碼
\path (2,-1.2) pic[scale=0.5,color=red] {relay};
它產生一個中心沒有標籤的圖形(出於好奇,它在無線通訊中被稱為中繼)。如何在中心實現類似於第一個範例(移動塔)的自訂標籤。
以下程式碼給出了完整的工作範例。
\documentclass[tikz]{standalone}
\usepackage{ellipsis}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing,decorations.markings,shapes.geometric}
\tikzset{naming/.style={align=center,font=\small}}
\tikzset{antenna/.style={insert path={-- coordinate (ant#1) ++(0,0.25) -- +(135:0.25) + (0,0) -- +(45:0.25)}}}
\tikzset{station/.style={naming,draw,shape=dart,shape border rotate=90, minimum width=10mm, minimum height=10mm,outer sep=0pt,inner sep=3pt}}
%\tikzset{mobile/.style={naming,draw,shape=rectangle,minimum width=15mm,minimum height=7.5mm, outer sep=0pt,inner sep=3pt}}
\tikzset{mobile/.style={naming,draw,shape=rectangle,minimum width=12mm,minimum height=6mm, outer sep=0pt,inner sep=3pt}}
%\tikzset{radiation/.style={{decorate,decoration={expanding waves,angle=90,segment length=4pt}}}}
%%%%%%%%%%%%%%%%%%%%%% RELAY %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{radiation/.style={{decorate,decoration={expanding waves,angle=90,segment length=4pt}}},
relay/.pic={
code={\tikzset{scale=5/10}
\draw[semithick] (0,0) -- (1,4);% left line
\draw[semithick] (3,0) -- (2,4);% right line
\draw[semithick] (0,0) arc (180:0:1.5 and -0.5);
\node[inner sep=4pt] (circ) at (1.5,5.5) {};
\draw[semithick] (1.5,5.5) circle(8pt);
\draw[semithick] (1.5,5.5cm-8pt) -- (1.5,4);
\draw[semithick] (1.5,4) ellipse (0.5 and 0.166);
\draw[semithick,radiation,decoration={angle=45}] (1.5cm+8pt,5.5) -- +(0:2);
\draw[semithick,radiation,decoration={angle=45}] (1.5cm-8pt,5.5) -- +(180:2);
}}
}
%%%%%%%%% MOBILE PHONE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\UE}[1]{%
\begin{tikzpicture}[every node/.append style={rectangle,minimum width=0pt}]
\node[mobile] (box) {#1};
\draw ([xshift=.25cm] box.south west) circle (4pt)
([xshift=-.25cm]box.south east) circle (4pt);
\fill ([xshift=.25cm] box.south west) circle (1pt)
([xshift=-.25cm]box.south east) circle (1pt);
\draw (box.north) [antenna=1];
\end{tikzpicture}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MOBILE BASE STATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\MBS}[1]{%
\begin{tikzpicture}[]
\node[station] (base) {#1};
%\draw[line join=bevel] (base.110) -- (base.70) -- (base.north west) -- (base.north east) -- cycle;
\draw[line join=bevel] (base.100) -- (base.80) -- (base.110) -- (base.70) -- (base.north west) -- (base.north east);
\draw[line join=bevel] (base.100) -- (base.70) (base.110) -- (base.north east);
% original yshift=.8pt
%\draw[line cap=rect] ([xshift=.5cm,yshift=.3pt] base.north) [antenna=1];
%\draw[line cap=rect] ([yshift=.3pt]ant1 |- base.north) -- node[above,shape=rectangle,inner ysep=+.3333em]{\dots} ([xshift=-.5cm,yshift=.3pt]base.north) [antenna=2];
\draw[line cap=rect] ([xshift=-.1768cm,yshift=.6pt]base.north -| base.right tail) [antenna=1];
\draw[line cap=rect] ([yshift=.6pt]ant1 |- base.north) -- node[above,shape=rectangle,inner ysep=+.3333em]{\dots} ([xshift=.1768cm,yshift=.6pt]base.north -| base.left tail) [antenna=2];
%\draw[line cap=rect] ([yshift=.3pt]ant1 |- base.north) -- ([xshift=-.5cm,yshift=.3pt]base.north) [antenna=2];
%\node at ($(ant1)!0.5!(ant2)$) {\dots};
\end{tikzpicture}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%% DIAGRAM STARTS HERE %%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}%[every path/.append style={thick}]
\draw (-4,0) ellipse (8 and 3);
\draw (8,0) ellipse (8 and 3);
\draw (-4,0) node[scale=2]{\MBS{a}} ;
\draw (8,0) node[scale=2,color=red]{\MBS{2}} ;
\path (2,1) pic[scale=0.5,color=red] {relay};
\path (2,-1.2) pic[scale=0.5,color=red] {relay};
\draw (1,0) node[scale=.8]{\UE{1}};
\draw (-1,0) node[scale=.8]{\UE{2}};
\end{tikzpicture}
\end{document}
答案1
像這樣的東西嗎?
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\tikzset{radiation/.style={{decorate,decoration={expanding waves,angle=90,segment length=4pt}}},
relay/.pic={
code={\tikzset{scale=5/10}
\draw[semithick] (0,0) -- (1,4);% left line
\draw[semithick] (3,0) -- (2,4);% right line
\draw[semithick] (0,0) arc (180:0:1.5 and -0.5) node[above, midway]{#1};
\node[inner sep=4pt] (circ) at (1.5,5.5) {};
\draw[semithick] (1.5,5.5) circle(8pt);
\draw[semithick] (1.5,5.5cm-8pt) -- (1.5,4);
\draw[semithick] (1.5,4) ellipse (0.5 and 0.166);
\draw[semithick,radiation,decoration={angle=45}] (1.5cm+8pt,5.5) -- +(0:2);
\draw[semithick,radiation,decoration={angle=45}] (1.5cm-8pt,5.5) -- +(180:2);
}}
}
\begin{document}
\begin{tikzpicture}
\path (2,-1.2) pic[scale=0.5,color=red] {relay=B};
\end{tikzpicture}
\end{document}