2011-06-08 137 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