I would like to draw the following deformed grid in Tikz.
I have written something that achieves visualisation of homogeneous deformations of a normal grid as in the following MWE, but it cannot handle drawing the deformed grid shown in the link.
Any approach would be appreciated but I would favour updating the \tikzset
to achieve this.
MWE
\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}
\foreach
loops, use a\node
instead of\filldraw
to make the circles, and then add two (shorter) loops afterwards to draw the connections between the nodes. Code is too long for comment, and doesn't answer the question, but see this Gist: gist.github.com/TorbjornT/5e76cefb7e401fea657291efc160182f