Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
easier grid connections
\documentclass[tikz]{standalone}
\usepackage{tikz}
\tikzset{
pics/grid/.style n args={9}{
code = {%
\pgfmathsetmacro \nxx{#6 - 1}
\pgfmathsetmacro \nyy{#7 - 1}
%CENTRAL DOT
\filldraw[black] circle (2pt) coordinate (-c);
% 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}
\node[circle,minimum size=5mm,fill=#1, draw=black, line width = 0.2mm] (-\i-\j) at (\x,\y) {};
}
}
% draw horizontal connections
\foreach [evaluate={\ii=int(\i+1)}] \i in {1,...,\nxx}
\foreach \j in {1,...,#7}
\draw [#1, dashed, line width = 0.2mm] (-\i-\j) -- (-\ii-\j);
% draw vertical connections
\foreach [evaluate={\jj=int(\j+1)}] \j in {1,...,\nyy}
\foreach \i in {1,...,#6}
\draw [#1, dashed, line width = 0.2mm] (-\i-\j) -- (-\i-\jj);
}}}
\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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.