从这个老问题开始如何在 tikz 中的圆形路径上绘制正弦波我根据我的兴趣修改了源代码:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{amsmath}
\begin{document}
\foreach \n in{3,4}{%
\begin{tikzpicture}
\begin{axis}[axis equal,
xmin=-3,xmax=3,
ymin=-3,ymax=3,
axis lines=none]
\addplot[samples=400,domain=0:2*pi,very thick,red] ({(2+.3*cos(deg(\n*x)))*cos(deg(x))},{(2+.3*cos(deg(\n*x)))*sin(deg(x))});
\addplot[samples=40,domain=0:2*pi,dashed] ({2*cos(deg(x))},{2*sin(deg(x))});
\node at (axis cs:0,0){$\color{blue}{\bullet}$};
\node at (axis cs:0,-1){$n=\n$};
\end{axis}
\end{tikzpicture}
}
\end{document}
我提出以下问题,希望能够得到您的帮助:
- 当数字
\n
发生变化时如何自动创建带有标签的波长。
(见下图)
- 如何创建德布罗意波(紫色),其核心始终与上一张图片中的相同。
非常感谢您的耐心和合作。我向您致以问候和感谢。
答案1
这是一项建议。当然,可以进一步调整它。请注意,我将循环变量重新定义为,\nn
否则语法就会出现问题calc
,您使用\n1
等。
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{amsmath}
\usetikzlibrary{decorations.markings,calc}
\begin{document}
\tikzset{mark two maxima/.style n args={3}{%
postaction=decorate,decoration={markings,
mark=at position #1 with {\draw[purple] (0,0) -- (0,-12pt) coordinate[midway] (x0);},
mark=at position #2 with {\draw[purple] (0,0) -- (0,-12pt) coordinate[midway](x1);
\draw let
\p1=($(x1)-(x0)$),\n1={atan2(\y1,\x1)},\n2={veclen(\x1,\y1)*(1/(2*sin(360*#2/2)))}
in [purple,rotate=-90+2*\n1,latex-latex] (x1)
arc({#2*360}:0:{(\n2)}) node[midway,fill=white]{#3};
;}}}}
\foreach \nn in{3,4}{%
\begin{tikzpicture}
\begin{axis}[axis equal,
xmin=-3,xmax=3,
ymin=-3,ymax=3,
axis lines=none]
\addplot[samples=400,domain=0:2*pi,very thick,red,
mark two maxima={0}{1/\nn}{$\lambda_{\nn}$}]
({(2+.3*cos(deg(\nn*x)))*cos(deg(x))},{(2+.3*cos(deg(\nn*x)))*sin(deg(x))});
\addplot[samples=40,domain=0:2*pi,dashed] ({2*cos(deg(x))},{2*sin(deg(x))});
\node at (axis cs:0,0){$\color{blue}{\bullet}$};
\node at (axis cs:0,-1){$n=\nn$};
\end{axis}
\end{tikzpicture}
}
\end{document}
特别服务:
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{subcaption}
\usepackage{floatrow}
\usepackage{pgfplots}
\usetikzlibrary{decorations.markings,calc}
\tikzset{mark two maxima/.style n args={3}{%
postaction=decorate,decoration={markings,
mark=at position #1 with {\draw[purple] (0,0) -- (0,-12pt) coordinate[midway] (x0);},
mark=at position #2 with {\draw[purple] (0,0) -- (0,-12pt) coordinate[midway](x1);
\draw let
\p1=($(x1)-(x0)$),\n1={atan2(\y1,\x1)},\n2={veclen(\x1,\y1)*(1/(2*sin(360*#2/2)))}
in [purple,rotate=-90+2*\n1,latex-latex] (x1)
arc({#2*360}:0:{(\n2)}) node[midway,fill=white]{#3};}}}}
\newcommand{\SebastianoPic}[1]{%
\begin{tikzpicture}
\begin{axis}[axis equal,
xmin=-3,xmax=3,
ymin=-3,ymax=3,
axis lines=none]
\addplot[samples=400,domain=0:2*pi,very thick,red,
mark two maxima={0}{1/#1}{$\lambda_{#1}$}]
({(2+.3*cos(deg(#1*x)))*cos(deg(x))},{(2+.3*cos(deg(#1*x)))*sin(deg(x))});
\addplot[samples=40,domain=0:2*pi,dashed] ({2*cos(deg(x))},{2*sin(deg(x))});
\node at (axis cs:0,0){$\color{blue}{\bullet}$};
\end{axis}
\end{tikzpicture}}
\begin{document}
\begin{figure}[htb]
\floatsetup{valign=t, heightadjust=all}
\ffigbox{%
\begin{subfloatrow}
\ffigbox{\SebastianoPic{3}}{\caption{$n=3$.\label{fig:n=3}}}
\ffigbox{\SebastianoPic{4}}{\caption{$n=4$.\label{fig:n=4}}}
\end{subfloatrow}}
{\caption{De Broglie waves.}\label{fig:DeBroglie}}
\end{figure}
\end{document}