2

A photodiode is typically depicted in the literature as a circle partially "hidden" by a rectangular bar. How does one go about drawing it with TiKz?

photodiode symbol

enter image description here

So far, I am using clip to "hide" part of a circle. Then, I superimpose a rectangle. The problem with this approach is that it simply masks the output (i.e., the resulting PDF still describes a full circle).

\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}

enter image description here

Sebastiano
  • 54,118
Mike D.
  • 131

1 Answers1

6

Make use of a \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}

enter image description here


Edit to exactly position the anchor coordinates (thanks to 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}

enter image description here