改编自我的“回答”这个问题:为什么单位乱了?我相信一定有解决办法。非常感谢!
\documentclass[tikz, border=1cm]{standalone}
\usepgfmodule{nonlineartransformations}
\makeatletter
\def\customtransformation{
\pgfmathsetmacro{\xnew}{
(2.7^\pgf@x)*cos(\pgf@y) % u = e^x * cos(y)
}
\pgfmathsetmacro{\ynew}{
(2.7^\pgf@x)*sin(\pgf@y) % v = e^x * sin(y)
}
\pgf@x=\xnew pt
\pgf@y=\ynew pt
}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{scope}[xshift=-6cm]
\draw[xstep=.5pt,ystep=5pt,black!25,thin] (0,0) grid (4pt,250pt);
\end{scope}
\pgftransformnonlinear{\customtransformation}
\draw[xstep=.5pt,ystep=5pt,black!25,thin] (0,0) grid (4pt,250pt);
\end{tikzpicture}
\end{document}
答案1
您似乎在寻找转换为厘米的方法。这可以通过将长度\pgf@x
和\pgf@y
除以来实现1cm
。从您的上一条评论中,我还了解到您希望在计算结束时转换回厘米单位。
\documentclass[tikz, border=1cm]{standalone}
\usepgfmodule{nonlineartransformations}
\usetikzlibrary{fpu}
\makeatletter
\newcommand{\PgfmathsetmacroFPU}[2]{\begingroup% https://tex.stackexchange.com/a/503835
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
\pgfmathsetmacro{#1}{#2}%
\pgfmathsmuggle#1\endgroup}%
\def\customtransformation{%
\PgfmathsetmacroFPU{\xnew}{%
(exp(\pgf@x/1cm))*cos(deg(\pgf@y/1cm))*1cm % u = e^x * cos(y)
}%
\PgfmathsetmacroFPU{\ynew}{%
(exp(\pgf@x/1cm))*sin(deg(\pgf@y/1cm))*1cm % v = e^x * sin(y)
}%
\pgf@x=\xnew pt%
\pgf@y=\ynew pt%
}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{scope}[xshift=-7cm]
\draw[black!25,thin] (0,0) grid (4,4);
\end{scope}
\draw[red] ({exp(1)*cos(deg(1))},{exp(1)*sin(deg(1))}) circle[radius=.1];
\pgfsettransformnonlinearflatness{3pt}
\pgftransformnonlinear{\customtransformation}
\draw[black!25,thin] (0,0) grid[step=0.25] (1,4);
\draw[blue,dashed] (1,1) circle[radius=.1];
\end{tikzpicture}
\end{document}
在这里我打开了fpu
库这里以防您使用更广泛的应用程序。还请注意,采样密度由维度控制\pgftransformnonlinearflatness
,可以使用设置\pgfsettransformnonlinearflatness
,请参阅第 1164 页的 pgfmanual v3.1.5:
因此,如果您希望减少网格步长,您可能还需要降低平坦度。毋庸置疑,降低平坦度会增加编译时间。