0

I am trying to draw a magnetic field diagram, but I am unsure how to draw arrows in the middle of bent and ellipse lines (desired output indicated by the yellow highlights).

Could anyone please suggest how to achieve this?

Thank you!

Current output

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{fancyhdr}
\usepackage{bigints}
\usepackage{color}
\usepackage{tcolorbox}
\usepackage{color,xcolor}
\usepackage{booktabs,array}
\usepackage{hyperref}
\usepackage{graphicx}
\usetikzlibrary{arrows}
\usepackage{polynom}
\usepackage{wallpaper}
\usepackage{flexisym}
\usepackage{caption}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{arrows.meta,decorations.markings}
\usetikzlibrary{arrows}
\usepgfplotslibrary{fillbetween}
\usepgfplotslibrary{statistics}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}

\begin{tikzpicture} %MAGNET \fillgray!60 rectangle (2.5,0.5); \fillgray!60 rectangle (8.0,0.5); % \node at (2.2,0) {\Large N}; \node at (5.8,0) {\Large S}; % \drawgray,thick -- (2.5,-0.5) -- (2.5,0.5) -- (0,0.5); \drawgray,thick -- (5.5,-0.5) -- (5.5,0.5) -- (8.0,0.5); % %MIDDLE \begin{scope} \drawthick,red arc (-180:-360:1.8cm and 2.2cm); \drawthick,red arc (-180:-360:1.7cm and 1.5cm); \drawthick,red arc (-180:-360:1.6cm and 0.9cm); % \drawthick, to [bend left=50] (5.5,+0.3); \drawthick, to [bend left=25] (5.5,+0.2); \drawthick, to [bend left=15] (5.5,+0.1); \drawthick, to [bend left=5] (5.5,+0.0); % \drawthick, to [bend right=5] (5.5,+0.0); \drawthick, to [bend right=15] (5.5,-0.1); \drawthick, to [bend right=25] (5.5,-0.2); \drawthick, to [bend right=50] (5.5,-0.3); % \drawthick,blue arc (-180:0:1.6cm and 0.9cm); \drawthick,blue arc (-180:0:1.7cm and 1.5cm); \drawthick,blue arc (-180:0:1.8cm and 2.2cm); \end{scope} % %LEFT MAGNET \drawthick,-latex to [bend left=20] (2.6,2.9); \drawthick,-latex to [bend left=5] (1.9,2.7); \drawthick,-latex to [bend right=5] (1.4,2.5); \drawthick,-latex to [bend right=13] (1.0,2.2); \drawthick,-latex to [bend right=15] (0.7,1.9); \drawthick,-latex to [bend right=17] (0.4,1.5); \drawthick,-latex to [bend right=27] (0.1,1.2); % \drawthick,-latex to [bend right=20] (2.6,-2.9); \drawthick,-latex to [bend right=5] (1.9,-2.7); \drawthick,-latex to [bend left=5] (1.4,-2.5); \drawthick,-latex to [bend left=13] (1.0,-2.2); \drawthick,-latex to [bend left=15] (0.7,-1.9); \drawthick,-latex to [bend left=17] (0.4,-1.5); \drawthick,-latex to [bend left=27] (0.1,-1.2); % %RIGHT MAGNET \drawthick, to [bend right=20] (8-2.6,2.9); \drawthick, to [bend right=5] (8-1.9,2.7); \drawthick, to [bend left=5] (8-1.4,2.5); \drawthick, to [bend left=13] (8-1.0,2.2); \drawthick, to [bend left=15] (8-0.7,1.9); \drawthick, to [bend left=17] (8-0.4,1.5); \drawthick, to [bend left=27] (8-0.1,1.2); % \drawthick, to [bend left=20] (8-2.6,-2.9); \drawthick, to [bend left=5] (8-1.9,-2.7); \drawthick, to [bend right=5] (8-1.4,-2.5); \drawthick, to [bend right=13] (8-1.0,-2.2); \drawthick, to [bend right=15] (8-0.7,-1.9); \drawthick, to [bend right=17] (8-0.4,-1.5); \drawthick, to [bend right=27] (8-0.1,-1.2); \end{tikzpicture} \end{document}

Will Kim
  • 2,032

1 Answers1

0

Thank you @Roland, this worked beautifully!

Remedied image

\tikzset{middlearrow/.style={
        decoration={markings,
            mark= at position 0.5 with {\arrow{#1}} ,
        },
        postaction={decorate}
    }
}   
\begin{tikzpicture}
%MAGNET
\fill[gray!60](0,-0.5) rectangle (2.5,0.5);
\fill[gray!60](5.5,-0.5) rectangle (8.0,0.5);
%
\node at (2.2,0) {\Large X};
\node at (5.8,0) {\Large Y};
%
\draw[gray,thick](0,-0.5) -- (2.5,-0.5) -- (2.5,0.5) -- (0,0.5);
\draw[gray,thick](8.0,-0.5) -- (5.5,-0.5) -- (5.5,0.5) -- (8.0,0.5);
%
%MIDDLE
\begin{scope}
\draw[thick,middlearrow={latex}](2.2,0.5) arc (-180:-360:1.8cm and 2.2cm);
\draw[thick,middlearrow={latex}](2.3,0.5) arc (-180:-360:1.7cm and 1.5cm);
\draw[thick,middlearrow={latex}](2.4,0.5) arc (-180:-360:1.6cm and 0.9cm);
%
\draw[thick,middlearrow={latex}](2.5,+0.3) to [bend left=50] (5.5,+0.3);
\draw[thick,middlearrow={latex}](2.5,+0.2) to [bend left=25] (5.5,+0.2);
\draw[thick,middlearrow={latex}](2.5,+0.1) to [bend left=15] (5.5,+0.1);
\draw[thick,middlearrow={latex}](2.5,+0.0) to [bend left=5] (5.5,+0.0);
%
\draw[thick,middlearrow={latex}](2.5,+0.0) to [bend right=5] (5.5,+0.0);
\draw[thick,middlearrow={latex}](2.5,-0.1) to [bend right=15] (5.5,-0.1);
\draw[thick,middlearrow={latex}](2.5,-0.2) to [bend right=25] (5.5,-0.2);
\draw[thick,middlearrow={latex}](2.5,-0.3) to [bend right=50] (5.5,-0.3);
%
\draw[thick,middlearrow={latex}](2.4,-0.5) arc (-180:0:1.6cm and 0.9cm);
\draw[thick,middlearrow={latex}](2.3,-0.5) arc (-180:0:1.7cm and 1.5cm);
\draw[thick,middlearrow={latex}](2.2,-0.5) arc (-180:0:1.8cm and 2.2cm);
\end{scope}
%
%LEFT MAGNET
\draw[thick,-latex](2.0,0.5) to [bend left=20] (2.6,2.9);
\draw[thick,-latex](1.9,0.5) to [bend left=5] (1.9,2.7);
\draw[thick,-latex](1.8,0.5) to [bend right=5] (1.4,2.5);
\draw[thick,-latex](1.6,0.5) to [bend right=13] (1.0,2.2);
\draw[thick,-latex](1.4,0.5) to [bend right=15] (0.7,1.9);
\draw[thick,-latex](1.1,0.5) to [bend right=17] (0.4,1.5);
\draw[thick,-latex](0.8,0.5) to [bend right=27] (0.1,1.2);
%
\draw[thick,-latex](2.0,-0.5) to [bend right=20] (2.6,-2.9);
\draw[thick,-latex](1.9,-0.5) to [bend right=5] (1.9,-2.7);
\draw[thick,-latex](1.8,-0.5) to [bend left=5] (1.4,-2.5);
\draw[thick,-latex](1.6,-0.5) to [bend left=13] (1.0,-2.2);
\draw[thick,-latex](1.4,-0.5) to [bend left=15] (0.7,-1.9);
\draw[thick,-latex](1.1,-0.5) to [bend left=17] (0.4,-1.5);
\draw[thick,-latex](0.8,-0.5) to [bend left=27] (0.1,-1.2);
%
%RIGHT MAGNET
\draw[thick,middlearrow={latex}](8-2.6,2.9) to [bend left=20] (8-2.0,0.5);
\draw[thick,middlearrow={latex}](8-1.9,2.7) to [bend left=5] (8-1.9,0.5);
\draw[thick,middlearrow={latex}](8-1.4,2.5) to [bend right=5] (8-1.8,0.5);
\draw[thick,middlearrow={latex}](8-1.0,2.2) to [bend right=13] (8-1.6,0.5);
\draw[thick,middlearrow={latex}](8-0.7,1.9) to [bend right=15] (8-1.4,0.5);
\draw[thick,middlearrow={latex}](8-0.4,1.5) to [bend right=17] (8-1.1,0.5);
\draw[thick,middlearrow={latex}](8-0.1,1.2) to [bend right=27] (8-0.8,0.5);
%
%
\draw[thick,middlearrow={latex}](8-2.6,-2.9) to [bend right=20] (8-2.0,-0.5);
\draw[thick,middlearrow={latex}](8-1.9,-2.7) to [bend right=5] (8-1.9,-0.5);
\draw[thick,middlearrow={latex}](8-1.4,-2.5) to [bend left=5] (8-1.8,-0.5);
\draw[thick,middlearrow={latex}](8-1.0,-2.2) to [bend left=13] (8-1.6,-0.5);
\draw[thick,middlearrow={latex}](8-0.7,-1.9) to [bend left=15] (8-1.4,-0.5);
\draw[thick,middlearrow={latex}](8-0.4,-1.5) to [bend left=17] (8-1.1,-0.5);
\draw[thick,middlearrow={latex}](8-0.1,-1.2) to [bend left=27] (8-0.8,-0.5);
\end{tikzpicture}
Will Kim
  • 2,032
  • 1
    You may consider defining tikzsets to avoid those very redundant [thick,middlearrow={latex}] blocks, & all. – SebGlav Jul 29 '21 at 11:10