答案1
为了让您入门,请看以下代码:我在圆圈上添加了边框锚点,并在形状上添加了一个锚点elmech
(将在未来的版本中做出类似的更改,这些锚点很有用)。(更改在 之间%%%
,代码取自pgfcirctripoles.tex
)。
将形状更改为与您的绘图相似应该很容易(但如果您这样做,请重命名它)。
\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\makeatletter
% electromechanical device (motor/generator)
\pgfdeclareshape{elmech}
{
\savedanchor\northwest{
\pgf@y=\pgfkeysvalueof{/tikz/circuitikz/tripoles/elmech/height}\pgf@circ@Rlen
\pgf@y=.5\pgf@y
\pgf@x=-\pgfkeysvalueof{/tikz/circuitikz/tripoles/elmech/width}\pgf@circ@Rlen
\pgf@x=.5\pgf@x
}
\anchor{center}{
\pgfpointorigin
}
\anchor{text}{
\pgfpointorigin
\advance \pgf@x by -.5\wd\pgfnodeparttextbox
\advance \pgf@y by -.5\ht\pgfnodeparttextbox
}
\anchor{left}{%
\northwest
\pgf@y=0pt
}
\anchor{right}{%
\northwest
\pgf@y=0pt
\pgf@x=-\pgf@x
}
\anchor{top}{
\northwest
\pgf@x=0pt
}
\anchor{pathstart}{
\northwest
\pgf@x=0pt
}
\anchor{pathend}{
\northwest
\pgf@x=0pt
\pgf@y=-\pgf@y
}
\anchor{bottom}{
\northwest
\pgf@x=0pt
\pgf@y=-\pgf@y
}
\anchor{center}{
\pgf@y=0pt
\pgf@x=0pt
}
\anchor{east}{
\northwest
\pgf@y=0pt
\pgf@x=-\pgf@x
}
\anchor{west}{
\northwest
\pgf@y=0pt
}
\anchor{south}{
\northwest
\pgf@x=0pt
\pgf@y=-\pgf@y
}
\anchor{north}{
\northwest
\pgf@x=0pt
}
\anchor{south west}{ \northwest \pgf@y=-\pgf@y }
\anchor{north east}{ \northwest \pgf@x=-\pgf@x }
\anchor{north west}{ \northwest }
\anchor{south east}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
%%%% added for here
\anchorborder{%
\@tempdima=\pgf@x\@tempdimb=\pgf@y
\northwest\pgf@circ@res@other=-\pgf@x
\pgfpointborderellipse{\pgfqpoint{\@tempdima}{\@tempdimb}}{\pgfqpoint{\pgf@circ@res@other}{\pgf@circ@res@other}}
}
\anchor{block down right}{
\northwest
\pgf@y=-0.85\pgf@y % we should calculate this better, let's go for now
\pgf@x=-0.5\pgf@x
}
%%%%
\backgroundpath{
\pgfsetcolor{\pgfkeysvalueof{/tikz/circuitikz/color}}
\pgf@circ@res@step=\ctikzvalof{tripoles/elmech/width}\pgf@circ@Rlen
\pgf@circ@res@up=\ctikzvalof{tripoles/elmech/height}\pgf@circ@Rlen
\pgfscope
\pgfstartlinewidth=\pgflinewidth
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfscope % clip the bar: whole size minus the circle
\pgfpathrectanglecorners{\pgfpoint{-.5\pgf@circ@res@step}{-.5\pgf@circ@res@up}}{\pgfpoint{.5\pgf@circ@res@step}{.5\pgf@circ@res@up}}
\pgfpathcircle{\pgfpoint{0}{0}} {0.5\pgf@circ@res@step}
\pgfseteorule
\pgfusepath{clip}
\pgfpathrectangle{\pgfpoint{-.25\pgf@circ@res@step}{-.5\pgf@circ@res@up}}{\pgfpoint{.5\pgf@circ@res@step}{\pgf@circ@res@up}}
\pgfsetfillcolor{black}
\pgfusepath{fill, draw}
\endpgfscope
\pgfpathcircle{\pgfpoint{0}{0}} {0.5\pgf@circ@res@step}
\ifx\tikz@fillcolor\pgfutil@empty
\pgfsetfillcolor{white}
\else
\pgfsetfillcolor{\tikz@fillcolor}
\fi
\pgfusepath{draw, fill}
\endpgfscope
}
}
\makeatother
\begin{document}
\begin{circuitikz}[
]
\node [elmech](M){ac};
\draw (M.180) -- ++(-.3,0) coordinate(a);
\draw (M.150) -- (M.150 -| a);
\draw (M.210) -- (M.210 -| a);
% \node [circle, fill=red, inner sep=.2pt] at (M.block down right){};
\draw (M.block down right) -- ++(0.3,0);
\end{circuitikz}
\end{document}
答案2
除了 Rmanos 方法之外,这是我的版本。现在上面有锚点,但无论如何它还是有用的。
\documentclass[border=10pt]{standalone}
\usepackage[pdftex]{graphicx} %% Grafikeinbindung
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}
\draw (-5, 0) circle (1cm);
\node [draw, thick, shape=rectangle, minimum width=0.4cm, minimum height=1.2cm, anchor=center] at (-5,0) {};
\draw (-5.2, 0.4) to (-4.8, 0.4);
\draw (-5, 0) ++(210:1cm) -- ++ (-0.2, -0.5) -- ++ (0, -0.5) -- ++ (2, 0);
\begin{scope}[yscale=1,xscale=-1]
\draw (5, 0) ++(210:1cm) -- ++ (-0.2, -0.5) -- ++ (0, -0.5) -- ++ (2, 0);
\end{scope}
\node[color=black, below] at (-5,-1.5) {PMSM};
\end{circuitikz}
%electrical machine
\end{document}