5

I would like to draw this image in Latex.

enter image description here

Here the arrows inside the ellipse represent dipoles. They are polarized by the magnetic field $B$. $d$ is the distance between the two ellipses.

Stefan Pinnow
  • 29,535

1 Answers1

9

Welcome to TeX.SE! The purpose of this site is to exchange codes and to ask for help if one is stuck with some LaTeX problem. This usually does not include asking others to translate a screen shot to LaTeX code. However, for newcomers sometimes exceptions are made.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d,shapes.geometric,shadows.blur}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
    \def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
    \def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
    \def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
    \tikz@canvas@is@plane}
\makeatother
\begin{document}
\tdplotsetmaincoords{60}{130}
\begin{tikzpicture}[tdplot_main_coords,>=latex,line join=bevel]
    \coordinate (O) at (0,0,0);
    \draw[thick,->] (O) -- (5,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (O) -- (0,5,0) node[anchor=north west]{$y$};
    \draw[thick,->] (O) -- (0,0,5) node[anchor=south]{$z$};
    \draw[dashed] (O) -- (-5,0,0);
    \begin{scope}[canvas is yz plane at x=5,transform shape]
     \node[ellipse,fill=blue,fill opacity=0.7,draw,minimum width=2cm,minimum height=8mm,
     rotate=65] (elliL) at (2,2) {};
     \path (elliL.west) -- (elliL.east) coordinate[pos=0.1] (L1b)
     coordinate[pos=0.3] (L1t) coordinate[pos=0.4] (L2b)
     coordinate[pos=0.6] (L2t) coordinate[pos=0.7] (L3b)
     coordinate[pos=0.9] (L3t);
     \foreach \X in {1,2,3}
     {\draw[thick,-latex] (L\X b) -- (L\X t);}
    \end{scope}
    \begin{scope}[canvas is yz plane at x=-1,transform shape]
     \node[ellipse,fill=blue,fill opacity=0.7,draw,minimum width=2cm,minimum height=8mm,
     rotate=80] (elliR) at (2,2) {};
     \path (elliR.west) -- (elliR.east) coordinate[pos=0.1] (R1b)
     coordinate[pos=0.3] (R1t) coordinate[pos=0.4] (R2b)
     coordinate[pos=0.6] (R2t) coordinate[pos=0.7] (R3b)
     coordinate[pos=0.9] (R3t);
     \foreach \X in {1,2,3}
     {\draw[thick,-latex] (R\X b) -- (R\X t);}
    \end{scope}
    % this is essentially from the tikz-3dplot manual p. 26-27
    \pgfmathsetmacro{\rvec}{7}
    \pgfmathsetmacro{\thetavec}{30}
    \pgfmathsetmacro{\phivec}{60}
    \tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
    \node[anchor=south west,color=red] at (P) {$B$};
    \draw[-stealth,color=red,very thick] (O) -- (P);
    \draw[dashed, color=red] (O) -- (Pxy);
    \draw[dashed, color=red] (P) -- (Pxy);
    \tdplotdrawarc{(O)}{1}{0}{\phivec}{anchor=north}{$\phi$}
    \tdplotsetthetaplanecoords{\phivec}
    \tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{1.5}{0}%
        {\thetavec}{anchor=-110}{$\theta$}
    %
    \begin{scope}[canvas is xy plane at z=0,blue!70]
    \path (5,2) -- (-1,2) node[midway,below] {$d$}; 
    \pgflowlevelsynccm% not necessary but maybe nicer
    \draw[ultra thick,latex-latex] (5,2) -- (-1,2);
    \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

I personally would not like to depend on others, the more so playing with these codes can be fun. Therefore, I'd like to encourage you to try to figure out what's going on here.

  • Use canvas is yx plane at z instead of canvas is xy plane at z (cf. https://tex.stackexchange.com/a/367560) – Henri Menke Nov 18 '18 at 01:41
  • @HenriMenke But I specifically use that plane to indicate that the distance is drawn in this plane, and I do load the fix for this plane. And I use Jake's fix which seems to be older than the fix you are referring to. Of course, I could switch to the other plane, but why would I? –  Nov 18 '18 at 01:46
  • On the bugtracker it was pointed out that the “broken” definition of xy plane might actually be deliberate: https://sourceforge.net/p/pgf/bugs/410/ – Henri Menke Nov 18 '18 at 01:48
  • @HenriMenke I guess that only Till Tantau will be able to clarify this. I do believe that it might be deliberate, but it might be for another reason: this was all written before the tikz-3dplot package was written. So one interpretation is that it was deliberate in order to enable non-orthographic projections, like the one in the OPs screen shot. However, I personally do not like non-orthographic projections, and prefer to share Jake's opinion that the original transformation is not the transformation one should use. Plus the 3d library has no official manual AFAIK. –  Nov 18 '18 at 01:54
  • @HenriMenke One more thing. If you ever want to transform texts, it would be somewhat unfortunate to have only one option for the projection. Yes, I know you can rectify this by adding further transformations like rotate=90, xscale=-1 and so on. However, I guess there is only one person who will ultimately be able to clarify this. A compromise might be to just add another library to CTAN with a slightly different syntax. Some days I think that this together with these macros might be useful for some. –  Nov 18 '18 at 02:10
  • 1
    For the record: Jake's patch is now incorporated in v3.1 of TikZ. – Stefan Pinnow Jan 15 '19 at 19:12