为什么形状会转移离子旋转?

为什么形状会转移离子旋转?

我想用 tikz 画一幅类似的画 在此处输入图片描述

到目前为止创建了一个自定义形状

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{wesys}[2013/10/16 Wesys Custom Package]

\RequirePackage{tikz}

\tikzset{arc style/.initial={}}

\pgfdeclareshape{windturbine}{
    \inheritsavedanchors[from=circle]
    \inheritanchorborder[from=circle]
    \inheritanchor[from=circle]{north}
    \inheritanchor[from=circle]{north west}
    \inheritanchor[from=circle]{north east}
    \inheritanchor[from=circle]{center}
    \inheritanchor[from=circle]{west}
    \inheritanchor[from=circle]{east}
    \inheritanchor[from=circle]{mid}
    \inheritanchor[from=circle]{mid west}
    \inheritanchor[from=circle]{mid east}
    \inheritanchor[from=circle]{base}
    \inheritanchor[from=circle]{base west}
    \inheritanchor[from=circle]{base east}
    \inheritanchor[from=circle]{south}
    \inheritanchor[from=circle]{south west}
    \inheritanchor[from=circle]{south east}
    \inheritanchor[from=circle]{center}

    \backgroundpath{
        \radius 
        \pgf@xa=\pgf@x 
        \centerpoint \pgf@xb=\pgf@x \pgf@yb=\pgf@y
        \pgfpathcircle{\centerpoint}{\radius/10}


        \pgfpathellipse{\pgfpointadd{\centerpoint}{\pgfpoint{\radius/2}{0pt}}}{\pgfpoint{\radius/2}{0}}{\pgfpoint{0}{\radius/20}}
        \pgfpathellipse{\pgfpointadd{\centerpoint}{\pgfpoint{-\radius/2}{0pt}}}{\pgfpoint{\radius/2}{0}}{\pgfpoint{0}{\radius/20}}

        \begingroup
            \tikz@mode

            \iftikz@mode@fill
                \iftikz@mode@draw
                    \pgfusepath{fill,draw}
                \else
                \pgfusepath{fill}
                    \fi
                \else
                        \iftikz@mode@draw
                    \pgfusepath{draw}
                \fi
            \fi
        \endgroup
    }
}

我开始画一幅类似上面的画

\documentclass{article}

\usepackage{tikz}
\usepackage{wesys}
\usetikzlibrary{positioning}
\makeatletter


\makeatother

\begin{document}
\begin{tikzpicture}
    \node[ windturbine, draw=black,dashed, minimum width=3cm, rotate=-10, xshift=5cm](turbineirot) {};
    \node[ windturbine, draw=black, fill=black, rotate=-40, xshift=5cm, minimum width=3cm,label={[midway,above]i}](turbinei) {};    

    \node[ windturbine, below=2cm of turbinei,rotate=-10, draw=black, fill=black, minimum width=3cm,label={[below= of turbinej, xshift=-8pt]j}](turbinej) {};

    \draw[-] (turbinei.center) -- (turbinej.center)node [midway,right,draw=none] {};
\end{tikzpicture}
\end{document}

当我旋转形状时,所有形状都会发生偏移,如何防止偏移?如何用标签绘制线条和用标签绘制角度?

答案1

这里问题的根源是xshift参数。您的形状并不完美(正如@JohnKormylo 在评论中提到的那样),但可以通过这种方式修复此问题(如果这是所需的输出)。

\begin{filecontents}{wesys.sty}
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{wesys}[2013/10/16 Wesys Custom Package]

\RequirePackage{tikz}

\tikzset{arc style/.initial={}}

\pgfdeclareshape{windturbine}{
    \inheritsavedanchors[from=circle]
    \inheritanchorborder[from=circle]
    \inheritanchor[from=circle]{north}
    \inheritanchor[from=circle]{north west}
    \inheritanchor[from=circle]{north east}
    \inheritanchor[from=circle]{center}
    \inheritanchor[from=circle]{west}
    \inheritanchor[from=circle]{east}
    \inheritanchor[from=circle]{mid}
    \inheritanchor[from=circle]{mid west}
    \inheritanchor[from=circle]{mid east}
    \inheritanchor[from=circle]{base}
    \inheritanchor[from=circle]{base west}
    \inheritanchor[from=circle]{base east}
    \inheritanchor[from=circle]{south}
    \inheritanchor[from=circle]{south west}
    \inheritanchor[from=circle]{south east}
    \inheritanchor[from=circle]{center}

    \backgroundpath{
        \radius 
        \pgf@xa=\pgf@x 
        \centerpoint \pgf@xb=\pgf@x \pgf@yb=\pgf@y
        \pgfpathcircle{\centerpoint}{\radius/10}


        \pgfpathellipse{\pgfpointadd{\centerpoint}{\pgfpoint{\radius/2}{0pt}}}{\pgfpoint{\radius/2}{0}}{\pgfpoint{0}{\radius/20}}
        \pgfpathellipse{\pgfpointadd{\centerpoint}{\pgfpoint{-\radius/2}{0pt}}}{\pgfpoint{\radius/2}{0}}{\pgfpoint{0}{\radius/20}}

        \begingroup
            \tikz@mode

            \iftikz@mode@fill
                \iftikz@mode@draw
                    \pgfusepath{fill,draw}
                \else
                \pgfusepath{fill}
                    \fi
                \else
                        \iftikz@mode@draw
                    \pgfusepath{draw}
                \fi
            \fi
        \endgroup
    }
}
\end{filecontents}
\documentclass{article}

\usepackage{tikz}
\usepackage{wesys}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
        \begin{scope}[xshift=5cm]
            \node[ windturbine, draw=black,dashed, minimum width=3cm, rotate=-10](turbineirot) {};
            \node[ windturbine, draw=black, fill=black, rotate=-40, minimum width=3cm,label={[midway,above]i}](turbinei) {};
        \end{scope};
    \node[ windturbine, below=2cm of turbinei,rotate=-10, draw=black, fill=black, minimum width=3cm,label={[below= of turbinej, xshift=-8pt]j}](turbinej) {};
    \draw[-] (turbinei.center) -- (turbinej.center)node [midway,right,draw=none] {};
\end{tikzpicture}
\end{document}

附言:您确实不需要那里的\makeatletter\makeatother命令。

PS:你可能会注意到这里使用 filecontents 环境来创建单部分 MWE

相关内容