我正在绘制一个涉及让路径绕行的光学实验。
使用 PSTricks 可以实现这一点,但我还没有找到使用 TikZ 实现这一点的方法。
我目前拥有的:
- 分束器和镜子采用相对节点定位。
- 只需定义节点的路径即可连接激光器。
到目前为止,我已经尝试了循环库(只能循环回到节点本身,就像状态图一样)、设置弯曲(不会转一整圈,只会稍微弯曲)、使用线圈装饰(到目前为止最好,但很丑,在纸上看起来不太好看)。
有没有人能给我一个可以帮我做这个事情的库?
编辑:我采纳了已接受的答案并做了一些调整。请注意,结束角度设置为垂直。
\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}
这将创建以下输出:
我仍需要修复箭头定位,但我正在努力。
答案1
可能的解决方案:
\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}
结果: