定义 PGF 形状

定义 PGF 形状

我对使用 tikz 还很陌生,但我还没有找到具有我所寻找形状的库。我的最终目标是制作一个像电路库一样的库,但用于热力学系统。我一直在尝试定义一个内接在圆上的三角形的形状(如下所示),但无法让它工作。

在此处输入图片描述

这是我的代码:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning, arrows, shapes.geometric}



\pgfdeclareshape{pump}{
    \inheritsavedanchors[from=[regular polygon=3]]
    \inheritsavedanchors[from=circle]
    \inheritanchorborder[from=circle]
    \inheritanchor[from=circle]{center}
    \inheritanchor[from=circle]{radius}
    \inheritanchor[from=circle]{north}
    \inheritanchor[from=circle]{east}
    \inheritanchor[from=circle]{south}
    \inheritanchor[from=circle]{west}
}

\begin{document}

\begin{tikzpicture}
    \node[shape=pump, draw]{};
\end{tikzpicture}

\end{document}

答案1

欢迎!您需要添加适当的背景路径。我也不确定是否有类似的东西

\inheritsavedanchors[from=[regular polygon=3]]

有效,至少我会感到惊讶。这是针对该形状的建议。

\documentclass[tikz,border=3mm]{standalone}
\makeatletter
\pgfdeclareshape{pump}{%
    \inheritsavedanchors[from=circle]%
    \inheritanchorborder[from=circle]%
    \inheritanchor[from=circle]{center}%
    \inheritanchor[from=circle]{radius}%
    \inheritanchor[from=circle]{north}%
    \inheritanchor[from=circle]{east}%
    \inheritanchor[from=circle]{south}%
    \inheritanchor[from=circle]{west}%
  \anchor{north corner}{%
  \pgf@x=0pt%
  \pgf@y=\radius%
  }%    
  \anchor{west corner}{%
  \pgf@xa=\radius
  \pgf@x=-0.866025\pgf@xa%
  \pgf@y=-0.5\pgf@xa%
  }%    
  \anchor{east corner}{%
  \pgf@xa=\radius
  \pgf@x=0.866025\pgf@xa%
  \pgf@y=-0.5\pgf@xa%
  }%    
  \backgroundpath{%
    \pgf@xa\radius% store radius in auxiliary length 
    \pgfpathmoveto{\pgfpoint{0pt}{\pgf@xa}}%
    \pgfpathlineto{\pgfpoint{0.866025\pgf@xa}{-0.5\pgf@xa}}%
    \pgfpathlineto{\pgfpoint{-0.866025\pgf@xa}{-0.5\pgf@xa}}%
    \pgfpathclose
    \pgfpathcircle{\pgfpointorigin}{\pgf@xa}%
  }}
\makeatother
\begin{document}

\begin{tikzpicture}
 \node[shape=pump, draw,minimum size=1cm] (p1) {};
 \node[shape=pump, draw=blue,minimum size=2cm] (p2) at (4,1){};
 \draw[red] (p1.north corner) to[out=90,in=-150] (p2.west corner);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容