使用 Tikz 绘制磁畴

使用 Tikz 绘制磁畴

我将使用tikz包绘制顺磁体和铁磁体的磁畴,如下图所示:

在此处输入图片描述

请考虑以下 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}

这是输出:

在此处输入图片描述

答案1

你可以使用随机变形的六边形格子来获得

\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}

在此处输入图片描述

相关内容