3

I have a minor inconvenience in the following drawing. I would like to change the arrowhead that shows the distance d to lie in the yz plane. I am unsure of how to do this if anyone can help me out that would be great. Image: enter image description here So to reiterate, I want for the arrows circled red in the following image to lie in the same plane as S1 and S2 lie: enter image description here Code:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{3d}

\begin{document}
    \begin{tikzpicture}[scale=1.25,every node/.append style={transform shape}]
        \foreach \x in {-1,-0.75,...,0} {
            \draw (\x,-1) -- (\x,1);
        }
        \draw[fill=black!10] (0.5,-2,-1) -- (0.5,-2,1) -- (0.5,2,1) -- (0.5,2,-1) -- (0.5,-2,-1);
        \fill (0.5,0,0) circle (0.05);
        \foreach \r in {0.25,0.5,...,1.75} {
            \draw (0.5,0) ++(-60:\r) arc (-60:60:\r);
        }
        \draw[fill=black!10] (2,-2,-1) -- (2,-2,1) -- (2,2,1) -- (2,2,-1) -- (2,-2,-1);
        \fill (2,0.5) circle (0.05) (2,-0.5) circle (0.05);
        \foreach \r in {0.25,0.5,...,2} {
            \draw (2,0.5) ++(-60:\r) arc (-60:60:\r);
            \draw (2,-0.5) ++(-60:\r) arc (-60:60:\r);
        }
        \draw[fill=black!10] (4,-2,-1) -- (4,-2,1) -- (4,2,1) -- (4,2,-1) -- (4,-2,-1);
%       LABELLING
            \begin{scope}[canvas is yz plane at x=2,rotate=-90]
                \node[above] at (0,0.5) {S${}_1$};
                \node[below] at (0,-0.5) {S${}_2$};
                \draw[|<->|] (-0.5,0.5) -- (-0.5,-0.5) node[midway,right=-0.1cm] {d};
            \end{scope}
            \begin{scope}[canvas is yz plane at x=0.5,rotate=-90]
                \node[below left=-0.1cm] at (0,0) {S${}_0$};
            \end{scope}
        \begin{scope}[xshift=4cm,yshift=2cm,rotate=-90,canvas is xy plane at z=0]
            \fill[white] (0,0) rectangle (4,4);
            \begin{axis}[
                width=5.575cm,
                xmin=-0.5,
                xmax=0.5,
                ticks=none
            ]
                \addplot [samples=1000,blue
                ]
                {(cos(deg(5*pi*sin(deg(x)))))^(2)*((sin(deg(4*pi*sin(deg(x)))))/(4*pi*sin(deg(x))))^(2)};
            \end{axis}
        \end{scope}
        \draw[thin,densely dashed,blue] (2,0) -- (6.9,0);
        \draw[thin,densely dashed,blue] (2,0) -- +(15:2.5);
        \draw[thin,densely dashed,blue] (2,0) -- +(-15:2.5);
        \draw[thin,densely dashed,blue] (2,0) -- +(32:2.5);
        \draw[thin,densely dashed,blue] (2,0) -- +(-32:2.5);
    \end{tikzpicture}
\end{document}

Bonus Question

The pgfplots image is not of high resolution even with 500 samples (see the apex) is it possible to reduce the number of samples but retain detail?

Some info about the diagram

The picture is of the physics phenomena diffraction. Specifically it depicts the famous Young's double slit experiment and shows the intensity curve across various angles from the centre of the two holes.

2
  • 1
    For the bonus question the smooth option might be what you are looking for. It provides me with an seemingly accurate ánd smooth graph with 500 points: \addplot [samples=500,blue,smooth]
    – Steyn W.
    Jan 8, 2019 at 10:53
  • @SteynW. ah yes, I seem to have forgotten about the smooth option. Thanks so much
    – sab hoque
    Jan 8, 2019 at 10:58

2 Answers 2

1

You are looking for \pgflowlevelsynccm, I think. (A very similar question has been asked here.)

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{3d}

\begin{document}
    \begin{tikzpicture}[scale=1.25,every node/.append style={transform shape}]
        \foreach \x in {-1,-0.75,...,0} {
            \draw (\x,-1) -- (\x,1);
        }
        \draw[fill=black!10] (0.5,-2,-1) -- (0.5,-2,1) -- (0.5,2,1) -- (0.5,2,-1) -- (0.5,-2,-1);
        \fill (0.5,0,0) circle (0.05);
        \foreach \r in {0.25,0.5,...,1.75} {
            \draw (0.5,0) ++(-60:\r) arc (-60:60:\r);
        }
        \draw[fill=black!10] (2,-2,-1) -- (2,-2,1) -- (2,2,1) -- (2,2,-1) -- (2,-2,-1);
        \fill (2,0.5) circle (0.05) (2,-0.5) circle (0.05);
        \foreach \r in {0.25,0.5,...,2} {
            \draw (2,0.5) ++(-60:\r) arc (-60:60:\r);
            \draw (2,-0.5) ++(-60:\r) arc (-60:60:\r);
        }
        \draw[fill=black!10] (4,-2,-1) -- (4,-2,1) -- (4,2,1) -- (4,2,-1) -- (4,-2,-1);
%       LABELLING
            \begin{scope}[canvas is yz plane at x=2,rotate=-90]
                \node[above] at (0,0.5) {S${}_1$};
                \node[below] at (0,-0.5) {S${}_2$};
                \pgflowlevelsynccm          
                \draw[|<->|] (-0.5,0.5) -- (-0.5,-0.5) node[midway,right=-0.1cm] {d};
            \end{scope}
            \begin{scope}[canvas is yz plane at x=0.5,rotate=-90]
                \node[below left=-0.1cm] at (0,0) {S${}_0$};
            \end{scope}
        \begin{scope}[xshift=4cm,yshift=2cm,rotate=-90,canvas is xy plane at z=0]
            \fill[white] (0,0) rectangle (4,4);
            \begin{axis}[
                width=5.575cm,
                xmin=-0.5,
                xmax=0.5,
                ticks=none
            ]
                \addplot [samples=1000,blue
                ]
                {(cos(deg(5*pi*sin(deg(x)))))^(2)*((sin(deg(4*pi*sin(deg(x)))))/(4*pi*sin(deg(x))))^(2)};
            \end{axis}
        \end{scope}
        \draw[thin,densely dashed,blue] (2,0) -- (6.9,0);
        \draw[thin,densely dashed,blue] (2,0) -- +(15:2.5);
        \draw[thin,densely dashed,blue] (2,0) -- +(-15:2.5);
        \draw[thin,densely dashed,blue] (2,0) -- +(32:2.5);
        \draw[thin,densely dashed,blue] (2,0) -- +(-32:2.5);
    \end{tikzpicture}
\end{document}

enter image description here

As for your comment: you already say every node/.append style={transform shape}, so all you need to do is to draw the circles as nodes. (You could also achieve this with \pgflowlevelsynccm but, according to my experience, it is probably better to only use it if there is no other option, and at the very end of a scope.)

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{3d}

\begin{document}
    \begin{tikzpicture}[scale=1.25,every node/.append style={transform shape}]
        \foreach \x in {-1,-0.75,...,0} {
            \draw (\x,-1) -- (\x,1);
        }
        \draw[fill=black!10] (0.5,-2,-1) -- (0.5,-2,1) -- (0.5,2,1) -- (0.5,2,-1) -- (0.5,-2,-1);
        \fill (0.5,0,0) circle (0.05);
        \foreach \r in {0.25,0.5,...,1.75} {
            \draw (0.5,0) ++(-60:\r) arc (-60:60:\r);
        }
        \draw[fill=black!10] (2,-2,-1) -- (2,-2,1) -- (2,2,1) -- (2,2,-1) -- (2,-2,-1);
        %\fill (2,0.5) circle (0.05) (2,-0.5) circle (0.05);
        \foreach \r in {0.25,0.5,...,2} {
            \draw (2,0.5) ++(-60:\r) arc (-60:60:\r);
            \draw (2,-0.5) ++(-60:\r) arc (-60:60:\r);
        }
        \draw[fill=black!10] (4,-2,-1) -- (4,-2,1) -- (4,2,1) -- (4,2,-1) -- (4,-2,-1);
%       LABELLING
            \begin{scope}[canvas is yz plane at x=2,rotate=-90]
                \node[circle,inner sep=0.5mm,fill,label=above:{S${}_1$}] at (0,0.5){};
                \node[circle,inner sep=0.5mm,fill,label=below:{S${}_2$}] at (0,-0.5) {};
                \draw[dash pattern=on 1.5pt off 1pt,thin] (-0.5,0.5) -- (0,0.5)
                (-0.5,-0.5) -- (0,-0.5);
                \pgflowlevelsynccm          
                \draw[|<->|] (-0.5,0.5) -- (-0.5,-0.5) node[midway,right=-0.1cm] {d};
            \end{scope}
            \begin{scope}[canvas is yz plane at x=0.5,rotate=-90]
                \node[below left=-0.1cm] at (0,0) {S${}_0$};
            \end{scope}
        \begin{scope}[xshift=4cm,yshift=2cm,rotate=-90,canvas is xy plane at z=0]
            \fill[white] (0,0) rectangle (4,4);
            \begin{axis}[
                width=5.575cm,
                xmin=-0.5,
                xmax=0.5,
                ticks=none
            ]
                \addplot [samples=1000,blue
                ]
                {(cos(deg(5*pi*sin(deg(x)))))^(2)*((sin(deg(4*pi*sin(deg(x)))))/(4*pi*sin(deg(x))))^(2)};
            \end{axis}
        \end{scope}
        \draw[thin,densely dashed,blue] (2,0) -- (6.9,0);
        \draw[thin,densely dashed,blue] (2,0) -- +(15:2.5);
        \draw[thin,densely dashed,blue] (2,0) -- +(-15:2.5);
        \draw[thin,densely dashed,blue] (2,0) -- +(32:2.5);
        \draw[thin,densely dashed,blue] (2,0) -- +(-32:2.5);
    \end{tikzpicture}
\end{document}

enter image description here

5
  • Would that command also be able to put the black circles in the plane of the rectangle?
    – sab hoque
    Jan 8, 2019 at 13:36
  • @sabhoque I added a proposal to transform the dots.
    – user121799
    Jan 8, 2019 at 13:44
  • The amount of stuff hidden somewhere in the manual for both TikZ and pgfplots never fails to surprise me. Someone should make a most unusual but useful commands in TikZ and pgfplots pdf file.
    – sab hoque
    Jan 8, 2019 at 13:46
  • I was wondering because you wrote "but, according to my experience, it is probably better to only use it if there is no other option, and at the very end of a scope." why do you recommend not using it?
    – sab hoque
    Jan 8, 2019 at 14:06
  • 1
    @sabhoque It can give unexpected results if you do too many transformation. cavas is ... plane always worked for me when using simple things like arrows. But if I add other transformations on top like rotate and subjected nodes to this low level stuff, results became unexpected. I guess that has to do with the fact that nodes involve a lot of low level pgf code, just look at the shapes.geometric library to appreciate that.
    – user121799
    Jan 8, 2019 at 14:10
2

NOTE: This is not a solution that answers the initial question, but rather a solution that satisfies what I want to communicate in the diagram

I suited the purpose of the diagram by editing the arrow into a set of lines. Code and image below:

    \begin{tikzpicture}[scale=1.5,every node/.append style={transform shape}]
        \foreach \x in {-0.5,-0.25,0} {
            \draw (\x,-1) -- (\x,1);
        }
        \foreach \x in {-0.375,-0.125,-0.125} {
            \draw[dashed] (\x,-1) -- (\x,1);
        }
        \draw[fill=black!10] (0.5,-2,-1) -- (0.5,-2,1) -- (0.5,2,1) -- (0.5,2,-1) -- (0.5,-2,-1);
        \fill (0.5,0,0) circle (0.05);
        \foreach \r in {0.25,0.5,...,1.75} {
            \draw (0.5,0) ++(-60:\r) arc (-60:60:\r);
        }
        \foreach \r in {0.125,0.375,...,1.875} {
            \draw[dashed] (0.5,0) ++(-60:\r) arc (-60:60:\r);
        }
        \draw[fill=black!10] (2,-2,-1) -- (2,-2,1) -- (2,2,1) -- (2,2,-1) -- (2,-2,-1);
        \fill (2,0.5) circle (0.05) (2,-0.5) circle (0.05);
        \foreach \r in {0.25,0.5,...,2} {
            \draw (2,0.5) ++(-60:\r) arc (-60:60:\r);
            \draw (2,-0.5) ++(-60:\r) arc (-60:60:\r);
        }
        \foreach \r in {0.125,0.375,...,2.125} {
            \draw[dashed] (2,0.5) ++(-60:\r) arc (-60:60:\r);
            \draw[dashed] (2,-0.5) ++(-60:\r) arc (-60:60:\r);
        }
        \draw (2,0.5,0.625) -- (2,0.5,0.5);
        \draw (2,-0.5,0.625) -- (2,-0.5,0.5);
        \draw (2,0.5,0.5) -- (2,-0.5,0.5);
        \draw[densely dotted] (2,0.5,0.5) -- (2,0.5,0);
        \draw[densely dotted] (2,-0.5,0.5) -- (2,-0.5,0);
        \draw[fill=black!10] (4,-2,-1) -- (4,-2,1) -- (4,2,1) -- (4,2,-1) -- (4,-2,-1);
        %       LABELLING
        \begin{scope}[canvas is yz plane at x=2,rotate=-90]
            \node[above] at (0,0.5) {S${}_1$};
            \node[below] at (0,-0.5) {S${}_2$};
            \node[left] at (-0.5,0) {d};
        \end{scope}
        \begin{scope}[canvas is yz plane at x=0.5,rotate=-90]
            \node[below left=-0.1cm] at (0,0) {S${}_0$};
        \end{scope}
        \begin{scope}[xshift=4cm,yshift=2cm,rotate=-90,canvas is xy plane at z=0]
            \fill[white] (0,0) rectangle (4,1);
            \begin{axis}[
                width=5.575cm,
                xmin=-0.62,
                xmax=0.62,
                ymin=0,
                ticks=none
            ]
                \addplot [samples=500,black,smooth
                ]
                    {(cos(deg(5*pi*sin(deg(x)))))^(2)*((sin(deg(4*pi*sin(deg(x)))))/(4*pi*sin(deg(x))))^(2)};
                \draw[thin, densely dashed,blue] (axis cs:0.1593,0.1327) -- (axis cs:0.1593,0);
                \draw[thin, densely dashed,blue] (axis cs:-0.1593,0.1327) -- (axis cs:-0.1593,0);
                \draw[thin, densely dashed,blue] (axis cs:0.3941,0.03938) -- (axis cs:0.3941,0);
                \draw[thin, densely dashed,blue] (axis cs:-0.3941,0.03938) -- (axis cs:-0.3941,0);
            \end{axis}
        \end{scope}
        \draw[thin,densely dashed,blue] (2,0) -- (6.9,0);
        \begin{scope}
            \clip (2,-2) rectangle (4,2);
            \draw[thin,densely dashed,blue] (2,0) --    +(15:4);
            \draw[thin,densely dashed,blue] (2,0) --    +(-15:4);
            \draw[thin,densely dashed,blue] (2,0) --    +(32:4);
            \draw[thin,densely dashed,blue] (2,0) --    +(-32:4);
            \draw[thin,densely dashed,red] (2,0) --     +(8:4);
            \draw[thin,densely dashed,red] (2,0) --     +(-8:4);
            \draw[thin,densely dashed,red] (2,0) --     +(24:4);    
            \draw[thin,densely dashed,red] (2,0) --     +(-24:4);               
        \end{scope}
    \end{tikzpicture}

enter image description here

(has some extra features I omitted from the original question as they made the code unnecessarily cluttered)

3
  • Thank you very much for the share. Very usefull for me. I'll add the lambda/d, change slit names ... that is why the tex source is so precious. You may upload it on tikz examples
    – Tinmarino
    Jun 23, 2020 at 3:02
  • 1
    @Tinmarino there's a few things in it that I believe don't make it perfect and hence I don't think it is worthy as an example. For example the red and blue lines don't actually pass through calculated crossing points and the pgfplot at the end is for angle not actual x displacement (hence it does not line up exactly).
    – sab hoque
    Jul 10, 2020 at 7:43
  • yes, you are right. Anyway I got redirected here easily with google image. Thanks again!
    – Tinmarino
    Jul 10, 2020 at 19:34

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.