pgf / tikz:如何计算x坐标之间的半距离?

时间:2011-06-08 12:53:27

标签: latex tikz pgf

我正在尝试创建一个像这样的新节点类型:

http://www.live-wtr.ru/leo/Tikz9.png

但不明白,如何计算x3 = x1 +(x2 - x1)/ 2

我试图这样做,但徒劳无功。

    \pgfdeclareshape{variant}{ \inheritsavedanchors[from=rectangle]
     % this is nearly a rectangle
     \inheritanchorborder[from=rectangle] \inheritanchor[from=rectangle]{center}
     \inheritanchor[from=rectangle]{north} \inheritanchor[from=rectangle]{south}
     \inheritanchor[from=rectangle]{west} \inheritanchor[from=rectangle]{east}

     \backgroundpath{
       %{{{ store lower left in xa/ya and upper right in xb/yb
       \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
       \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
   %}}}

       % compute x3 --- here is the problem!
       \pgf@yc = \pgf@xb - \pgf@xa
       \pgf@yc = 0.5\pgf@yc
       \pgf@xc = \pgf@xa
       \advance \pgf@xc by \pgf@yc

   %end of the problem

       \pgf@yc = \pgf@ya
       \advance\pgf@yc by - 10pt % this should be a parameter

       \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
       %{{{ construct 2 bottom lines
       \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
       \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
       \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
   %}}}

       % Rectangle box
       \pgfpathrectanglecorners{\southwest}{\northeast}

     }
   }

1 个答案:

答案 0 :(得分:0)

您可以使用PGF数学引擎进行计算。

% compute x3 --- here is the problem!

\pgfmathparse{(\pgf@xb-\pgf@xa)/2}
\pgf@xc=\pgf@xa
\advance\pgf@xc by \pgfmathresult pt

%end of the problem