我对选项有疑问transform shape nonlinear=true
,可以在 pgfmanual 第 123 页找到。(请注意,这个问题最初是这个先前的问题。然而,@cfr 发现实际上有两个独立的问题,并且可以在这个精彩的答案。我仍然觉得需要报告另一个问题,所以我在这里发布它。如果您认为我应该删除此帖子,我很乐意删除此帖子,特别是如果您是@cfr。)此屏幕截图中描述了该问题,MWE 如下:
\documentclass{article}
\usepackage{tikz}
\usepgfmodule{nonlineartransformations}
\makeatletter
\def\polartransformation{% from the pgfmanual section 103.4.2
\pgfmathsincos@{\pgf@sys@tonumber\pgf@x}%
\pgf@x=\pgfmathresultx\pgf@y%
\pgf@y=\pgfmathresulty\pgf@y%
} % note that the problem is not specific to this transformation
\makeatother
\begin{document}
\section*{Ordinary linear transformations}
It is well known that one can refer to coordinates inside a scope subject to
linear transformations without problems, regardless of whether or not one installs an
ordinary \texttt{transform shape}.
\begin{tikzpicture}
\begin{scope}[xshift=-4cm]
\draw (-1,0) coordinate (l1) -- (3,1) coordinate (l2);
\end{scope}
\begin{scope}[transform shape]
\draw (-1,0) coordinate (n1) -- (3,1) coordinate (n2);
\end{scope}
\node[circle,draw] (A) at (-1,-2) {A};
\node[circle,draw] (B) at (2,-2) {B};
\draw[blue] (A) -- (l1) (A) -- (n1);
\draw[red] (B) -- (l2) (B) -- (n2);
\end{tikzpicture}
\section*{Ordinary nonlinear transformations}
This is also true for ``ordinary'' nonlinear transformations.
\begin{tikzpicture}
\begin{scope}
\pgftransformnonlinear{\polartransformation}
\draw (-1,0) coordinate (m1) -- (3,1) coordinate (m2); % no, m does not stand for marmot ;-)
\end{scope}
\node[circle,draw] (A) at (-1,-2) {A};
\node[circle,draw] (B) at (2,-2) {B};
\draw[blue] (A) -- (m1);
\draw[red] (B) -- (m2);
\end{tikzpicture}
\section*{Nonlinear transformations with \texttt{transform shape nonlinear=true}}
However, once one adds \texttt{transform shape nonlinear=true}, this does no
longer work.
\begin{tikzpicture}
\begin{scope}[transform shape nonlinear=true] % p. 234 of the pgf manual
\pgftransformnonlinear{\polartransformation}
\draw (-1,0) coordinate (r1) -- (3,1) coordinate (r2);
\end{scope}
\node[circle,draw] (A) at (-1,-2) {A};
\node[circle,draw] (B) at (2,-2) {B};
\draw[blue] (A) -- (r1);
\draw[red] (B) -- (r2);
\end{tikzpicture}
On the other hand, one might need these things, as only with this option
switched on the shape gets transformed.
\begin{tikzpicture}[baseline=(A.base)]
\begin{scope}
\pgftransformnonlinear{\polartransformation}
\node[draw] (n1) at (2,2){hello!};
\end{scope}
\node[circle,draw] (A) at (-1,-2) {A};
\node[circle,draw] (B) at (2,-2) {B};
\draw[blue] (A) -- (n1.west);
\draw[red] (B) -- (n1.east);
\end{tikzpicture}\quad vs.\quad
\begin{tikzpicture}[baseline=(A.base)]
\begin{scope}[transform shape nonlinear=true]
\pgftransformnonlinear{\polartransformation}
\node[draw] (n2) at (2,2){hello!};
\end{scope}
\node[circle,draw] (A) at (-1,-2) {A};
\node[circle,draw] (B) at (2,-2) {B};
\draw[blue] (A) -- (n2.west);
\draw[red] (B) -- (n2.east);
\end{tikzpicture}
\end{document}
请注意,此选项非常有用(IMHO)。
在左图中,坐标可以正确访问,但节点形状没有变换,而在第二种情况下,节点可以变换,但坐标无法正确访问。看来 Ti钾Z没有正确存储坐标的绝对位置。
问题: 有可能有 Ti钾Z 是否正确存储绝对坐标,即就像所有其他情况一样?
笔记:选项本身在 中定义tikz.code.tex
(而不是在 中pgfmodulenonlineartransformations.code.tex
)。
\tikzset{
transform shape nonlinear/.is choice,
transform shape nonlinear/.default=true,
transform shape nonlinear/true/.code=\let\tikz@nlt\relax,
transform shape nonlinear/false/.code=\def\tikz@nlt{\pgfapproximatenonlineartranslation},
transform shape nonlinear=false
}
对我来说有点奇怪的是默认设置似乎是,true
但是当 Ti钾Z 已加载,它被设置为 false。
答案1
\makeatletter
\tikzdeclarecoordinatesystem{polar}{
\tikz@scan@one@point\relax(#1)
\polartransformation
}
\begin{tikzpicture}[baseline=(A.base)]
\begin{scope}[transform shape nonlinear=true]
\pgftransformnonlinear{\polartransformation}
\node[draw] (n2) at (2,2){hello!};
\end{scope}
\node[circle,draw] (A) at (-1,-2) {A};
\node[circle,draw] (B) at (2,-2) {B};
\draw[blue] (A) -- (polar cs:n2.west);
\draw[red] (B) -- (polar cs:n2.east);
\end{tikzpicture}