请问,我想在我的 circuitikz 图纸中添加一个 PIR(运动)传感器。我在官方手册或互联网上找不到任何东西,有什么想法吗?
答案1
以下代码定义了一个新的 circuitikz 形状以及一些有用的锚点。参数pir/height
、pir/pitch
和pir/width
允许pir/radius
更改新形状的大小。
\documentclass{article}
\usepackage{circuitikz}
\makeatletter
\ctikzset{
pir/height/.initial=1.4cm,
pir/pitch/.initial=0.6cm,
pir/width/.initial=0.5cm,
pir/radius/.initial=0.5cm
}
\pgfdeclareshape{pir}{
\anchor{center}{\pgfpointorigin}
\savedanchor\topleft{%
\pgf@y=\pgfkeysvalueof{/tikz/circuitikz/pir/pitch}
\pgf@x=\pgfkeysvalueof{/tikz/circuitikz/pir/width}
\pgf@x=-1.5\pgf@x
}
\anchor{power}{\topleft}
\anchor{out}{\topleft\pgf@y=0pt}
\anchor{ground}{\topleft\pgf@y=-\pgf@y}
\savedanchor\top{%
\pgf@y=\pgfkeysvalueof{/tikz/circuitikz/pir/height}
\pgf@y=.5\pgf@y
\pgf@x=\pgfkeysvalueof{/tikz/circuitikz/pir/width}
\pgf@x=-.5\pgf@x
}
\anchor{north}{\top}
\anchor{south}{\top\pgf@y=-\pgf@y}
\anchor{east}{\pgf@y=0pt\pgf@x=\pgfkeysvalueof{/tikz/circuitikz/pir/radius}}
\savedanchor\topleftbox{%
\pgf@y=\pgfkeysvalueof{/tikz/circuitikz/pir/height}
\pgf@y=0.5\pgf@y
\pgf@x=\pgfkeysvalueof{/tikz/circuitikz/pir/width}
\pgf@x=-\pgf@x
}
\foregroundpath{
\pgfsetcolor{\pgfkeysvalueof{/tikz/circuitikz/color}}
\pgfsetlinewidth{2\pgflinewidth}
\topleftbox
\pgf@circ@res@up=\pgfkeysvalueof{/tikz/circuitikz/pir/height}
\pgf@circ@res@up=0.5\pgf@circ@res@up
\pgf@circ@res@down=-\pgf@circ@res@up
\pgf@circ@res@left=\pgfkeysvalueof{/tikz/circuitikz/pir/width}
\pgf@circ@res@left=-\pgf@circ@res@left
\pgf@circ@res@right=0cm
\pgfpathrectanglecorners{
\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}
}{
\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}
}
\pgf@circ@res@right=\pgf@circ@res@left
\pgfpathmoveto{\pgfpoint{0pt}{\pgfkeysvalueof{/tikz/circuitikz/pir/radius}}}
\pgfpatharc{90}{-90}{\pgfkeysvalueof{/tikz/circuitikz/pir/radius}}
\pgfusepath{draw}
\topleft
\pgf@circ@res@up=\pgf@y
\pgf@circ@res@left=\pgf@x
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{ \pgf@circ@res@up}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{ \pgf@circ@res@up}}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@up}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{-\pgf@circ@res@up}}
\pgfsetlinewidth{.5\pgflinewidth}
\pgfusepath{draw}
}}
\makeatother
\begin{document}
\begin{circuitikz}
\draw (0,0) node[pir] (pir) {}
(pir.power) node[anchor=east] {power}
(pir.ground) node[anchor=east] {ground}
(pir.out) node[anchor=east] {output}
(pir.north) node[anchor=south] {north}
(pir.south) node[anchor=north] {south}
(pir.east) node[anchor=west] {east};
\end{circuitikz}
\end{document}