8

I am drawing an optical experiment that involves making a path take a detour.

Looped path

This is possible with PSTricks, but I haven't found a way to achieve this with TikZ.

What I currently have:

  • The beam splitter and mirror are positioned with relative node positioning.
  • The lasers are connected simply by defining paths from nodes.

So far I've tried the loop library (can only loop back to the node itself, like a state diagram), setting bends (will not turn one whole turn, just bend slightly), using a coil decoration, (best so far, but ugly and won't look good in the paper).

Does anybody have a pointer to a library that could do this for me?

Edit: I have taken the accepted answer and done a few tweaks. Note that the end angles are set to vertical.

\documentclass[tikz]{standalone}

\usetikzlibrary{
    positioning,
    arrows,
    decorations.markings,
    hobby
}
\colorlet{maroon}{red!80!black}

\tikzstyle{beamsplitter} = [
    fill=gray,
    fill opacity=0.3,
]

\tikzstyle{left-hand-mirror} = [
    draw,
    postaction=decorate, 
    decoration={
        markings,
        mark=between positions 0.015 and 0.98 step 0.1072 with {\draw (0,0)--(60:3pt);}
    }
]   

\tikzstyle{laser} = [
    draw=maroon,
    line cap=round,
]

\tikzstyle{laserarrow} = [
    line cap=round,
    draw=maroon,
    decoration={markings,mark=at position 0.55 with{\arrow[rotate=-20,maroon]{latex'}}},
    postaction={decorate},
    mark options={color=maroon}
]

\begin{document}

\begin{tikzpicture}[use Hobby shortcut]
    \node (source) {};  

    \node[right=1cm of source] (splitter) {}; 

    \node[above=1 cm of splitter] (mirror) {};
    \node[right=5mm of splitter] (combiner) {};
    \node[right=5mm of mirror] (end) {};

    \path[laser] (source.east) -- (splitter.center);

    \path[laser] (mirror.center) -- (end.center) {};

    \path[laser] (splitter.center) -- (combiner.center);

% Create a node to the left of the midway between the splitter and mirror
    \path (splitter) -- (mirror.center) node[midway,left]
    (midway) {};

% Create a node to the left of the above node
    \node [left = 5mm of midway] (midway-left) {};

% Create the loop
    \draw [laserarrow]
    ([out angle=90, in angle=-90]splitter.center) .. (midway) .. (midway-left) 
    .. (midway) .. (mirror.center);

    \path[left-hand-mirror] (mirror.south west) --
    (mirror.north east) ;

    \draw[beamsplitter] (splitter.north west) rectangle (splitter.south east);
    \draw (splitter.north east) -- (splitter.south west);
\end{tikzpicture}

\end{document}

and this creates the following output:

Final result

I still need to fix that arrow positioning, but I'm getting there.

  • 1
    Welcome to TeX.SX! We normally don't put greetings in questions so I removed yours. – Svend Tveskæg Feb 19 '14 at 13:10
  • 1
    Search for hobby in this site. – user11232 Feb 19 '14 at 13:16
  • Harish, thanks for the suggestion for the hobby package. It might be a good answer for my question, however it refuses to work on MiKTeX 2.9 even though I am using the latest package version. Not even an MWE compiles. Should I ask a separate question about this? The error message in question is "Undefined Control Sequence" withouth telling me which control sequence is undefined. – Jonathan Jogenfors Feb 19 '14 at 13:51
  • I intended this as a comment but do not have the prerequisite reputation to make comments. Did any one answering this consider controls ? If not was there a reason, other then it's a bit fiddly. \tikz draw (0,0) .. controls (3,1) and (-2,1).. (1,0); – Carel Aug 3 '15 at 8:51
5

A possible solution:

\documentclass[tikz,border=10pt,png]{standalone}
\usetikzlibrary{backgrounds,calc,decorations.markings,hobby}
\pgfdeclarelayer{foreground}
\pgfsetlayers{main,foreground}
\colorlet{maroon}{red!80!black}

\begin{document}
\begin{tikzpicture}[use Hobby shortcut]
%\draw[help lines] (-1,-1) grid (4,3);

\draw[thick,maroon] (0,0) -- (2.75,0);

\begin{pgfonlayer}{foreground}% to avoid:
% http://tex.stackexchange.com/q/156613/13304
\node[thick,inner sep=5pt,fill,draw,fill opacity=0.2](n) at (2,0){};
\draw[thick,
  shorten <=\pgflinewidth, 
  shorten >=\pgflinewidth
 ]
 (n.south west)--(n.north east);
\end{pgfonlayer}

\draw[thick,maroon, 
 postaction=decorate, 
 decoration={markings,mark= at position 0.44 with 
  {\arrow[rotate=-12]{stealth};}}
 ] 
 (2,0) .. (1.75,1) .. (1.6,1.25) .. (1,1) .. 
 (1.6,0.75)..([tension=-2]2,2)--(2.75,2);

\draw[thick] (2,2)--($(2,2)!0.25!(1,1)$)coordinate(a)
(2,2)--($(2,2)!0.25!(3,3)$) coordinate(b);

\path[ 
 postaction=decorate, 
 decoration={markings,mark=between positions 0 and 1 step 4pt
  with {\draw[thick] (0,0)--(70:3pt);}}
 ]
 (a)--(b);

\end{tikzpicture}
\end{document}

The result:

enter image description here

  • Interesting! However, I seem to be having trouble with the hobby package on my Windows computer as per my above comment. Please allow me to look into this issue before I can accept your answer. – Jonathan Jogenfors Feb 19 '14 at 14:03
  • 1
    @JonathanFors: sure, no problem at all. Please check your hobby version: mine is 1.4 from 2014-01-21. Also notice that hobby is implemented in LaTeX3, hence you should have an updated version of expl3, xparse and pml3array. – Claudio Fiandrino Feb 19 '14 at 14:07
  • I am still not able to compile the document. I have submitted a separate question here: tex.stackexchange.com/questions/161282/… – Jonathan Jogenfors Feb 19 '14 at 14:47
  • It now works, and your solution was spot on. – Jonathan Jogenfors Feb 19 '14 at 15:37
  • 1
    By the way, pml3array ("Poor Man's LaTeX3 Array") is one of the files installed by the hobby package. – Loop Space Feb 19 '14 at 21:47

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.