建立自訂符號:菱形/菱形

建立自訂符號:菱形/菱形

我讀了這篇小文章:http://www.elfsoft2000.com/projects/bipole.pdf以及本文中提到的另外兩個。我想創建一個在我的論文和專案中使用的符號。在我的國家,其中一些與歐洲或美國的不同,所以我決定自己製作。

我設法找到了兩個羅馬尼亞電路符號,如下所示:github.com/PopAdi/ Circuitikz-romanian-symbols

現在我必須做類似的事情:應該有一個菱形/菱形而不是圓形。我怎樣才能做到這一點?我希望它們看起來像這裡展示的那樣:Circuitikz 美國控制電壓標誌

在我的程式碼中,對於帶有圓圈的程式碼:

\pgfpathellipse{\pgfpointorigin}{\pgfpoint{0cm}{\ResUp}}{\pgfpoint{\ResRight}{0cm}}

我成功地用這個做了一個正方形:

\pgfpathrectanglecorners{\southwest}{\northeast}

但我真的不知道如何旋轉那個正方形或用鑽石改變它。你能幫我解決這個問題嗎?謝謝!

編輯:我的程式碼如下所示:

\documentclass{article}  

\usepackage{tikz}
\usepackage{circuitikz}
\usetikzlibrary{shapes,arrows,positioning}
\usetikzlibrary{decorations.markings}

\makeatletter
\pgf@circ@Rlen = \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
\def\TikzBipolePath#1#2{\pgf@circ@bipole@path{#1}{#2}}
\makeatother

\newlength{\ResUp} 
\newlength{\ResRight}

\ctikzset{bipoles/romanianCCS/height/.initial=.60}
\ctikzset{bipoles/romanianCCS/width/.initial=.60}


\pgfcircdeclarebipole{} 
    {\ctikzvalof{bipoles/romanianCCS/height}}
    {romanianCCS}
    {\ctikzvalof{bipoles/romanianCCS/height}}
    {\ctikzvalof{bipoles/romanianCCS/width}}
    {
        \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

        \pgfextracty{\ResUp}{\northeast}
        \pgfextractx{\ResRight}{\southwest}

        %Desenam cerculetul
        \pgfpathrectanglecorners{\southwest}{\northeast}

        %First little arrow
        \pgfmoveto{\pgfpoint{1.0\ResRight}{0.0\ResUp}}
        \pgflineto{\pgfpoint{0.1\ResRight}{0.0\ResUp}} 
        \pgflineto{\pgfpoint{0.3\ResRight}{-0.25\ResUp}} 
        \pgfmoveto{\pgfpoint{0.1\ResRight}{0.0\ResUp}}   
        \pgflineto{\pgfpoint{0.3\ResRight}{0.25\ResUp}}  

        %Second arrow
        \pgfmoveto{\pgfpoint{-0.2\ResRight}{0.0\ResUp}}
        \pgflineto{\pgfpoint{-1.0\ResRight}{0.0\ResUp}}
        \pgfmoveto{\pgfpoint{0.0\ResRight}{0.25\ResUp}}
        \pgflineto{\pgfpoint{-0.2\ResRight}{0.0\ResUp}}
        \pgflineto{\pgfpoint{0.0\ResRight}{-0.25\ResUp}}

        \pgfusepath{draw}
    }

\def\romanianCCS#1{\TikzBipolePath{romanianCCS}{#1}}
\tikzset{romanianCCS/.style = {\circuitikzbasekey, /tikz/to path=\romanianCCS, l=#1}}


\begin{document}

\begin{center}
\begin{circuitikz} 
\draw (0, 0) 
      to[romanianCCS, l=${j_1 = 4A}$, *-*] (4, 0);
\end{circuitikz}
\end{center}

\end{document}

這應該會給你以下結果:

在此輸入影像描述

我找到解決方案了!我這樣做了:

\pgftransformrotate{-45}
\pgfpathrectanglecorners{\southwest}{\northeast}
\pgftransformrotate{45}

而且效果很好!

答案1

如果您想要菱形而不是菱形,您可以使用:

\documentclass{article}  

\usepackage{tikz}
\usepackage{circuitikz}
\usetikzlibrary{shapes,arrows,positioning}
\usetikzlibrary{decorations.markings}

\makeatletter
\pgf@circ@Rlen = \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
\def\TikzBipolePath#1#2{\pgf@circ@bipole@path{#1}{#2}}
\makeatother

\newlength{\ResUp} 
\newlength{\ResRight}

\ctikzset{bipoles/romanianCCS/height/.initial=.60}
\ctikzset{bipoles/romanianCCS/width/.initial=.60}


\pgfcircdeclarebipole{} 
    {\ctikzvalof{bipoles/romanianCCS/height}}
    {romanianCCS}
    {\ctikzvalof{bipoles/romanianCCS/height}}
    {\ctikzvalof{bipoles/romanianCCS/width}}
    {
        \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

        \pgfextracty{\ResUp}{\northeast}
        \pgfextractx{\ResRight}{\southwest}

        %Desenam cerculetul
        \pgfpathmoveto{\pgfpoint{-\ResRight}{0pt}}
        \pgfpathlineto{\pgfpoint{0pt}{-\ResUp}}
        \pgfpathlineto{\pgfpoint{\ResRight}{0pt}}
        \pgfpathlineto{\pgfpoint{0pt}{\ResUp}}
        \pgfpathclose

        %First little arrow
        \pgfpathmoveto{\pgfpoint{1.0\ResRight}{0.0\ResUp}}
        \pgfpathlineto{\pgfpoint{0.1\ResRight}{0.0\ResUp}} 
        \pgfpathlineto{\pgfpoint{0.3\ResRight}{-0.25\ResUp}} 
        \pgfpathmoveto{\pgfpoint{0.1\ResRight}{0.0\ResUp}}   
        \pgfpathlineto{\pgfpoint{0.3\ResRight}{0.25\ResUp}}  

        %Second arrow
        \pgfpathmoveto{\pgfpoint{-0.2\ResRight}{0.0\ResUp}}
        \pgfpathlineto{\pgfpoint{-1.0\ResRight}{0.0\ResUp}}
        \pgfpathmoveto{\pgfpoint{0.0\ResRight}{0.25\ResUp}}
        \pgfpathlineto{\pgfpoint{-0.2\ResRight}{0.0\ResUp}}
        \pgfpathlineto{\pgfpoint{0.0\ResRight}{-0.25\ResUp}}

        \pgfusepath{draw}
    }

\def\romanianCCS#1{\TikzBipolePath{romanianCCS}{#1}}
\tikzset{romanianCCS/.style = {\circuitikzbasekey, /tikz/to path=\romanianCCS, l=#1}}


\begin{document}

\begin{center}
\begin{circuitikz} 
\draw (0, 0) 
      to[romanianCCS, l=${j_1 = 4A}$, *-*] (4, 0);
\end{circuitikz}
\end{center}

\end{document}

示範

相關內容