2011-06-08 104 views
1

我想创建一个新的节点类型是这样的:pgf/tikz:如何计算x坐标之间的一半距离?

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 \[email protected]=\[email protected] \[email protected]=\[email protected] 
     \northeast \[email protected]=\[email protected] \[email protected]=\[email protected] 
    %}}} 

     % compute x3 --- here is the problem! 
     \[email protected] = \[email protected] - \[email protected] 
     \[email protected] = 0.5\[email protected] 
     \[email protected] = \[email protected] 
     \advance \[email protected] by \[email protected] 

    %end of the problem 

     \[email protected] = \[email protected] 
     \advance\[email protected] by - 10pt % this should be a parameter 

     \southwest \[email protected]=\[email protected] \[email protected]=\[email protected] 
     %{{{ construct 2 bottom lines 
     \pgfpathmoveto{\pgfpoint{\[email protected]}{\[email protected]}} 
     \pgfpathlineto{\pgfpoint{\[email protected]}{\[email protected]}} 
     \pgfpathlineto{\pgfpoint{\[email protected]}{\[email protected]}} 
    %}}} 

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

    } 
    } 

回答

0

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

% compute x3 --- here is the problem! 

\pgfmathparse{(\[email protected]\[email protected])/2} 
\[email protected]=\[email protected] 
\advance\[email protected] by \pgfmathresult pt 

%end of the problem 
+0

当我使用它,我有一个“警告:在向后兼容模式下运行(不适合刻度标记;缺少的功能)考虑编写\ pgfplotsset {COMPAT = 1.8}到你的序言”。如果我这样做,我还有一个问题:“不完整\ iffalse;所有文本被忽略......” – Antonin 2014-04-09 20:02:32