在文献中,光电二极管通常被描绘成一个部分被矩形条“隐藏”的圆圈。如何使用 TiKz 绘制它?
到目前为止,我使用clip
“隐藏”圆的一部分。然后,我叠加一个矩形。这种方法的问题在于它只是掩盖了输出(即,生成的 PDF 仍然描述了一个完整的圆)。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\clip (0,0) rectangle (10mm,10mm);
\draw[inner color=orange!20, outer color=orange, draw, very thick] (2.5mm,5mm) circle (4mm);
\draw[fill] (0,0) rectangle (1.2mm,10mm);
\end{tikzpicture}
\end{document}
答案1
利用\pic
:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\tikzset{
pics/photo diode/.style={
code={
\tikzset{photo diode/.cd, #1}
\path[photo diode/bulb]
({-sqrt(3)*0.225},0)
arc[start angle=210, end angle=-30, radius=0.45]
-- cycle;
\path[photo diode/base] (-0.5,0) -- (0.5,0);
\coordinate (-north) at (0,0.675);
\coordinate (-south) at (0,0);
}
},
photo diode/base/.style={
draw,
line width=4pt
},
photo diode/bulb/.style={
draw,
ball color=orange
}
}
\begin{document}
\begin{tikzpicture}
\pic (P) at (0,0) {photo diode};
\pic[red] (Q) at (2,0) {photo diode={
bulb/.append style={ball color=green}
}};
\draw (P-south) -- ++(0,-0.5) -| (Q-south);
\end{tikzpicture}
\end{document}
编辑以精确定位锚点坐标(感谢 Sebastiano):
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\tikzset{
pics/photo diode/.style={
code={
\tikzset{photo diode/.cd, #1}
\path[photo diode/bulb]
({-sqrt(3)*0.225},0)
arc[start angle=210, end angle=-30, radius=0.45]
coordinate[midway, yshift={0.5*\pgflinewidth}] (-north);
\path[photo diode/base] (-0.5,0) -- (0.5,0)
coordinate[midway, yshift={-0.5*\pgflinewidth}] (-south);
}
},
photo diode/base/.style={
draw,
line width=4pt
},
photo diode/bulb/.style={
draw,
ball color=orange
}
}
\begin{document}
\begin{tikzpicture}
\pic (P) at (0,0) {photo diode};
\pic[red] (Q) at (2,0) {photo diode={
bulb/.append style={ball color=green}
}};
\draw (P-south) -- ++(0,-0.5) -| (Q-south);
\end{tikzpicture}
\end{document}