極座標會導致 TikZ 中的錯位嗎?

極座標會導致 TikZ 中的錯位嗎?

我正在嘗試使用極坐標對齊兩條路徑:

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}
    \path [fill=blue] (0,0) -- +(-135:5mm) -- ([turn]90:25mm) -- ([turn]90:5mm) -- cycle;
    \path [fill=red] (0,0) -- +(-135:5mm) -- ([turn]90: 5mm) -- ([turn]90:5mm) -- cycle;
\end{tikzpicture}

\end{document}

然而,它們略有偏差:

(下圖是經過裁剪和放大的)

在此輸入影像描述

我是否錯過了,即這裡誤算了什麼?

答案1

問題是這麼老PGF 的不準確之處馬克·維布羅(Mark Wibrow)很久以前就指出了這一點。如果我們應用它的校正,\pgfpointnormalised我們不僅可以獲得更好的正交投影精度,而且還可以獲得更好的精度[turn]

\documentclass[tikz]{standalone}
\usetikzlibrary{spy}

% use the Mark Wibrow's correction
\makeatletter
\def\pgfpointnormalised#1{%
  \pgf@process{#1}%
  \pgfmathatantwo{\the\pgf@y}{\the\pgf@x}%
  \let\pgf@tmp=\pgfmathresult%
  \pgfmathcos@{\pgf@tmp}\pgf@x=\pgfmathresult pt\relax%
  \pgfmathsin@{\pgf@tmp}\pgf@y=\pgfmathresult pt\relax%
}
\makeatother

\begin{document}
  \begin{tikzpicture}[spy using outlines={circle, magnification=7, size=17mm, connect spies}]

    \path [draw=blue] (0,0) -- +(-135:5mm) -- ([turn]90:25mm) -- ([turn]90:5mm) -- cycle;
    \path [draw=red] (0,0) -- +(-135:5mm) -- ([turn]90: 5mm) -- ([turn]90:5mm) -- cycle;

    \spy on (-45:5mm) in node at (2,-.5);
  \end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容