答案1
是的,通过非线性变换。
\documentclass[tikz, border=0.5cm]{standalone}
\usepgfmodule{nonlineartransformations}
\makeatletter
\def\latticetilt{%
\pgf@xa=\pgf@x%
\pgf@ya=\pgf@y%
%\typeout{old\space x=\pgf@xa\space old \space y=\pgf@ya}%
\pgfmathsetmacro{\myx}{\pgf@xa+\pgfkeysvalueof{/tikz/lattice/amplitude}*sin((\pgf@ya/\pgfkeysvalueof{/tikz/lattice/spacing})*360/\pgfkeysvalueof{/tikz/lattice/superlattice period})}%
\pgf@x=\myx pt%
\pgfmathsetmacro{\myy}{\pgf@ya+\pgfkeysvalueof{/tikz/lattice/amplitude}*sin((\pgf@xa/\pgfkeysvalueof{/tikz/lattice/spacing})*360/\pgfkeysvalueof{/tikz/lattice/superlattice period})}%
%\typeout{at\space x=\the\pgf@xa:\space new\space y=\myy}%
\pgf@y=\myy pt}
\begin{document}
\begin{tikzpicture}[lattice/.cd,spacing/.initial=5,superlattice
period/.initial=30,amplitude/.initial=3]
\begin{scope}[xshift=-6cm]
\draw[red] (0,0) grid (5,5);
\draw[->, black] (0,0) -- +(5,0);
\draw[->, black] (0,0) -- +(0,5);
\end{scope}
\begin{scope}
\pgftransformnonlinear{\latticetilt}
\draw[red] (0,0) grid (5,5);
\draw[->, black] (0,0) -- +(5,0);
\draw[->, black] (0,0) -- +(0,5);
\end{scope}
\end{tikzpicture}
\end{document}
其工作原理是安装一个转换,在本例中,\latticetilt
它将转换x
和y
坐标,\pgf@x
和\pgf@y
。您需要用有点神秘的 TeX 语法编写它。(这不是绝对必要的,写一些不那么神秘的东西并不太难,但编译可能会花费更长时间。)这个名字的原因superlattice
是我从这里,这是一个小的变化这个。此动画说明了amplitude
键的作用。(它还具有pic
用于坐标系的功能,因此,如果您想并排显示未转换的图片和转换后的图片,只需更改一次代码即可。)
\documentclass[tikz, border=0.5cm]{standalone}
\usepgfmodule{nonlineartransformations}
\makeatletter
\def\latticetilt{%
\pgf@xa=\pgf@x%
\pgf@ya=\pgf@y%
%\typeout{old\space x=\pgf@xa\space old \space y=\pgf@ya}%
\pgfmathsetmacro{\myx}{\pgf@xa+\pgfkeysvalueof{/tikz/lattice/amplitude}*sin((\pgf@ya/\pgfkeysvalueof{/tikz/lattice/spacing})*360/\pgfkeysvalueof{/tikz/lattice/superlattice period})}%
\pgf@x=\myx pt%
\pgfmathsetmacro{\myy}{\pgf@ya+\pgfkeysvalueof{/tikz/lattice/amplitude}*sin((\pgf@xa/\pgfkeysvalueof{/tikz/lattice/spacing})*360/\pgfkeysvalueof{/tikz/lattice/superlattice period})}%
%\typeout{at\space x=\the\pgf@xa:\space new\space y=\myy}%
\pgf@y=\myy pt}
\tikzset{pics/.cd,cs/.style={code={
\draw[red] (0,0) grid (#1,#1);
\draw[stealth-stealth, thick] (0,#1) |- (#1,0);
\draw[->, black] (0,0) -- +(0,5);
}},cs/.default=5}
\begin{document}
\foreach \X in {1,...,8,7,6,...,2}
{\begin{tikzpicture}[lattice/.cd,spacing/.initial=5,superlattice
period/.initial=30,amplitude/.initial=\X]
\path[use as bounding box] (-7.1,-0.1) rectangle (5.1,5.1);
\begin{scope}[xshift=-7cm]
\pic{cs};
\end{scope}
\begin{scope}
\pgftransformnonlinear{\latticetilt}
\pic{cs};
\end{scope}
\draw[very thick,-latex] (-1.9,2.5) -- (-0.1,2.5);
\end{tikzpicture}}
\end{document}
但请注意,非线性变换是非线性的。特别是,如果你移动物体,它的形状就会改变。你可能会遇到dimension too large
问题等等,但对于装饰等来说也是如此。