10

I am going to draw magnetic domain for paramagnet and ferromagnet as shown in figure below with tikz package:

enter image description here

Please consider the following MWE:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc,decorations,decorations.pathreplacing}

\newcommand{\bacterium}[2]{
\begin{scope}[rotate=#2]
\coordinate (A) at (#1);
\draw[-latex](A)++(0,.75*.5)--++(-.75,0);
\end{scope}
}

\begin{document}
\begin{tikzpicture}
\draw[](-6,-6)rectangle(6,6);
\foreach \x in {1,2,...,40}{\bacterium{rand*5,rand*5}{rand*360}}
\end{tikzpicture}
\end{document}

This is the output:

enter image description here

18

You can use a randomly deformed hexagonal lattice to get

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.arrows}
\tikzset{marrow/.style={red,fill, minimum height=3cm, single arrow, single arrow
    head extend=.5cm, single arrow head indent=.25cm,xscale=0.3,yscale=0.15}}
\begin{document}
\begin{tikzpicture}
 \clip (1,2) rectangle (7.5,12);
 \path foreach \X in {0,...,12}
 {foreach \Y in {0,...,9}
 {({0.75*\X+ifthenelse(isodd(\X),-1,1)*0.25+0.2*(2*rnd-1)},
 {\Y*sqrt(3)+ifthenelse(isodd(\X),-1,1)*sqrt(3)/4+0.2*(2*rnd-1)})
 coordinate[overlay] (p\X\Y)
 }};
 \foreach \X in {1,3,5,7,9}
 {\foreach \Y in {1,...,7} 
 {\ifodd\Y
 \draw (p\the\numexpr\X-1\relax\Y) coordinate(aux1)
 -- (p\X\Y) coordinate(aux2)
 -- (p\the\numexpr\X+1\relax\the\numexpr\Y-1\relax) coordinate(aux3)
 --  (p\the\numexpr\X+2\relax\Y) coordinate(aux4)
 --  (p\the\numexpr\X+1\relax\Y) coordinate(aux5)
 -- (p\X\the\numexpr\Y+1\relax) coordinate(aux6) -- cycle;
 \else
 \draw (p\X\Y) coordinate(aux1) -- 
 (p\the\numexpr\X+1\relax\the\numexpr\Y-1\relax) coordinate(aux2) -- 
 (p\the\numexpr\X+2\relax\Y) coordinate(aux3) -- 
 (p\the\numexpr\X+1\relax\Y) coordinate(aux4) --
 (p\X\the\numexpr\Y+1\relax) coordinate(aux5) -- 
 (p\the\numexpr\X-1\relax\Y) coordinate(aux6) -- cycle;
 \fi
 \path (barycentric cs:aux1=1,aux2=1,aux3=1,aux4=1,aux5=1,aux6=1) node[rotate=rnd*360,marrow]{};
 }}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • I have upvoted your answer now. Is it possible to put your code into box (of Schrödinger's cat)? :-) – Sebastiano Aug 17 '19 at 20:22
  • I know this is an old thread, but can someone explain the code, or point out where to look for more information? Thanks in advance! – Nikos Dec 20 '19 at 0:59
  • @Nikos It is hard to explain the code if one does not know which part you do not understand. This code generates lattice points which are shifted by some random distances, and connects them. The result is deformed hexagonal lattice. In each cell at the barycenter of the nodes of the cell boundary an arrow is placed that points in a random direction. – user194703 Dec 20 '19 at 1:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.