我怎样才能在 Tikz 中绘制这个网格

我怎样才能在 Tikz 中绘制这个网格

我想在 Tikz 中绘制以下变形网格。

在此处输入图片描述

我已经编写了一些东西,可以实现正常网格均匀变形的可视化,如下面的 MWE 所示,但它无法处理链接中显示的变形网格的绘制。

任何方法都将受到赞赏,但我赞成更新\tikzset以实现这一目标。

平均能量损失

\documentclass[tikz]{standalone}
\usepackage{pgfplots} 
\usetikzlibrary{arrows,shapes,backgrounds,fit,decorations.pathreplacing,chains,snakes,positioning,angles,quotes}  
\usepackage{amsmath,amssymb,bm}

\pgfplotsset{compat=1.10}

\tikzset{
pics/grid/.style n args={9}{
code = {%       
    \pgfmathsetmacro \nxx{#6 - 1}
    \pgfmathsetmacro \nyy{#7 - 1}       

    %CENTRAL DOT
    \filldraw[black] circle (2pt) coordinate (-c); 

    % DASHED GRID VERTICAL  
    \foreach \i in {1,...,#6}{
        \foreach \j in {1,...,\nyy}{
            \pgfmathsetmacro \x {(\i - (#6 + 1)/2)*#8*#2 + (\j - (#7 + 1)/2)*#9*#3} 
            \pgfmathsetmacro \y {(\i - (#6 + 1)/2)*#8*#4 + (\j - (#7 + 1)/2)*#9*#5}

            \pgfmathsetmacro \xt {(\i - (#6 + 1)/2)*#8*#2 + (\j+1 - (#7 + 1)/2)*#9*#3} 
            \pgfmathsetmacro \yt {(\i - (#6 + 1)/2)*#8*#4 + (\j+1 - (#7 + 1)/2)*#9*#5}

            \draw [#1, dashed, line width = 0.2mm] (\x,\y) -- (\xt,\yt);
            }
    }

    % DASHED GRID HORIZONTAL
    \foreach \i in {1,...,\nxx}{
        \foreach \j in {1,...,#7}{
            \pgfmathsetmacro \x {(\i - (#6 + 1)/2)*#8*#2 + (\j - (#7 + 1)/2)*#9*#3} 
            \pgfmathsetmacro \y {(\i - (#6 + 1)/2)*#8*#4 + (\j - (#7 + 1)/2)*#9*#5}

            \pgfmathsetmacro \xt {(\i+1 - (#6 + 1)/2)*#8*#2 + (\j - (#7 + 1)/2)*#9*#3} % Use the macros to calculate positions
            \pgfmathsetmacro \yt {(\i+1 - (#6 + 1)/2)*#8*#4 + (\j - (#7 + 1)/2)*#9*#5}

            \draw [#1, dashed, line width = 0.2mm] (\x,\y) -- (\xt,\yt);
            }
    }   

    % SOURCES
    \foreach \i in {1,...,#6}{
        \foreach \j in {1,...,#7}{
            \pgfmathsetmacro \x {(\i - (#6 + 1)/2)*#8*#2 + (\j - (#7 + 1)/2)*#9*#3} 
            \pgfmathsetmacro \y {(\i - (#6 + 1)/2)*#8*#4 + (\j - (#7 + 1)/2)*#9*#5}

            \filldraw[fill=#1, draw=black, line width = 0.2mm] (\x,\y) circle (2.5mm) coordinate (-\i-\j);
        }
    }   
}}}

\begin{document}

%% PROPERTIES OF THE GRID
\def \nx{4}
\def \ny{3}
\def \dx{3}
\def \dy{2.2}

%% IDENTITY. UNDEFORMED ARRAY
\def \ai{1}     
\def \bi{0}
\def \ci{0}  
\def \di{1}

%% STRETCHING DEFORMATION MATRIX 
\def \af{0.8} 
\def \bf{0}
\def \cf{0}  
\def \df{1.2}

\begin{tikzpicture}
\pic (a) {grid={blue!15!white}{\ai}{\bi}{\ci}{\di}{\nx}{\ny}{\dx}{\dy}};
\pic (b) {grid={orange!75!red}{\af}{\bf}{\cf}{\df}{\nx}{\ny}{\dx}{\dy}};
\end{tikzpicture}

\end{document}

答案1

您可以在 TikZ 中使用非线性变换。

\documentclass[tikz]{standalone}
\usepgfmodule{nonlineartransformations}
\makeatletter
\def\mytransformation{\pgfmathparse{abs(exp(\pgf@y/100))}\pgf@x=\pgfmathresult\pgf@x}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{scope}%Inside the scope transformation is active
\pgftransformnonlinear{\mytransformation}
\draw (-3,0mm) grid [step=1] (3,5);
\draw[red,ultra thick] (0,0) -- (3,5);
\end{scope}
% Here back to normal
\draw[blue,ultra thick] (0,0) -- (3,5);
\end{tikzpicture}
\end{document}

在此处输入图片描述

在这里,我基本上用当前 y 坐标的对数除以 100 来缩放 x 坐标,只是为了演示。

相关内容