有没有办法用 Latex 绘制这个图表?它是一个 3D 单位螺旋,它的 2D 投影显示它由正弦和余弦函数组成。
从这个答案我找到了如何绘制正弦和余弦函数的方法。但我不知道如何将其与 3D 螺旋线结合起来。
\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}%
[grid=both,
minor tick num=2,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt,draw=gray!50},
axis lines=middle,
enlargelimits={abs=0.2}
]
\addplot[domain=0:2,samples=50,smooth,red] {cos(deg(pi*x))};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}%
[grid=both,
minor tick num=2,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt,draw=gray!50},
axis lines=middle,
enlargelimits={abs=0.2}
]
\addplot[domain=0:2,samples=50,smooth,red] {sin(deg(pi*x))};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
好问题!简单但有点乏味tikz-3dplot
。有些元素我不知道它们有什么用处,所以我省略了它们,但一旦我更好地理解了,我会很乐意添加它们。(编辑:增加了注释和粗线。)
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc}
\begin{document}
\tdplotsetmaincoords{72}{120}
\begin{tikzpicture}[tdplot_main_coords,scale=0.8]
\pgfmathsetmacro{\Length}{3}
\pgfmathsetmacro{\Stretch}{2}
% \draw[-latex] (0,0,0) -- (\Length,0,0) node[below]{$x$};
% \draw[-latex] (0,0,0) -- (0,\Length,0) node[left]{$y$};
% \draw[-latex] (0,0,0) -- (0,0,\Length) node[left]{$z$};
\draw[red,very thick] plot[smooth,variable=\x,domain=0:720,samples=360] ({\Length*cos(\x)},
{\x*(\Stretch*\Length/360)},{-\Length*sin(\x)});
\node[red,font=\Large\sffamily] at (-0.8*\Length,\Length,-1.4*\Length)
{Helix};
\draw (-1.2*\Length,0,-1.2*\Length) coordinate (lbf) --
(1.2*\Length,0,-1.2*\Length) coordinate (lbb) --
(1.2*\Length,0,1.2*\Length) coordinate (ltb) --
(-1.2*\Length,0,1.2*\Length) coordinate (ltf) -- cycle;
\foreach \X in {bf,bb,tb,tf}
{\draw (l\X) -- ++ (0,2*\Stretch*\Length,0) coordinate (m\X);}
\draw[very thick,fill=white,fill opacity=0.5] (mbf) -- (mbb) -- (mtb) -- (mtf) -- cycle;
\foreach \X in {bf,bb,tf}
{\draw[very thick] (m\X) -- ++ (0,2*\Stretch*\Length,0) coordinate (r\X);}
% middle
\path (mbb) node[below=3pt,font=\Large\sffamily] {Circle};
\draw[-latex] ($(mtf)+(0,0,0.4)$) -- ++ (0,0.5*\Length,0)
node[midway,above,sloped,font=\sffamily] {time};
\foreach \X in {1,...,5}
{\ifnum\X=3
\draw[very thick] ($(mbf)!{\X/6}!(mbb)$) -- ++ (0,3*\Stretch*\Length,0);
\draw[very thick] ($(mbf)!{\X/6}!(mtf)$) -- ++ (0,3*\Stretch*\Length,0);
\else
\draw ($(mbf)!{\X/6}!(mbb)$) -- ++ (0,3*\Stretch*\Length,0);
\draw ($(mbf)!{\X/6}!(mtf)$) -- ++ (0,3*\Stretch*\Length,0);
\fi}
\foreach \X [evaluate=\X as \Y using {int(mod(\X,5))}] in {1,...,18}
{
\ifnum\Y=0
\draw[very thick] ($(mbf)+(0,\X,0)$) -- ($(mbb)+(0,\X,0)$);
\draw[very thick] ($(mbf)+(0,\X,0)$) -- ($(mtf)+(0,\X,0)$);
\else
\draw ($(mbf)+(0,\X,0)$) -- ($(mbb)+(0,\X,0)$);
\draw ($(mbf)+(0,\X,0)$) -- ($(mtf)+(0,\X,0)$);
\fi
}
\draw[thick] plot[smooth,variable=\x,domain=0:360]
({\Length*cos(\x)},2*\Stretch*\Length,{-\Length*sin(\x)});
\foreach \X in {1,...,12}
{
\draw[thick] (0,2*\Stretch*\Length,0)
--
({\Length*cos(\X*(360/12))},2*\Stretch*\Length,{-\Length*sin(\X*(360/12))});
}
\draw[red,very thick] plot[smooth,variable=\x,domain=720:1440,samples=360] ({\Length*cos(\x)},
{\x*(\Stretch*\Length/360)},{-\Length*sin(\x)});
\draw[blue,very thick] plot[smooth,variable=\x,domain=720:1800,samples=360]
({\Length*cos(\x)},{\x*(\Stretch*\Length/360)},-1.2*\Length);
\draw[blue,very thick] plot[smooth,variable=\x,domain=720:1800,samples=360]
(-1.2*\Length,{\x*(\Stretch*\Length/360)},{-\Length*sin(\x)});
% right
\foreach \X in {bf,bb,tf}
{\draw[very thick] (r\X) -- ++ (0,\Stretch*\Length,0);}
\path (rbb) node[below=3pt,font=\Large\sffamily] {Cosine};
\path (rtf) node[above=3pt,font=\Large\sffamily] {Sine};
\path (mtb) -- ++ (0,2*\Stretch*\Length,0) coordinate (rtb);
\draw[very thick,fill=white,fill opacity=0.5] (rbf) -- (rbb) -- (rtb) -- (rtf) -- cycle;
\draw[thick,fill=white,fill opacity=0.5] plot[smooth,variable=\x,domain=0:360]
({\Length*cos(\x)},4*\Stretch*\Length,{-\Length*sin(\x)});
\foreach \X in {1,...,12}
{
\draw[thick] (0,4*\Stretch*\Length,0)
--
({\Length*cos(\X*(360/12))},4*\Stretch*\Length,{-\Length*sin(\X*(360/12))});
}
\end{tikzpicture}
\end{document}
更新:我几乎忘记了强制动画。;-)(不幸的是,上传限制对 gif 的质量有一定影响。)
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc}
\begin{document}
\tdplotsetmaincoords{72}{120}
\foreach \Phase in {0,10,...,350}
{\begin{tikzpicture}[tdplot_main_coords,scale=0.8]
\pgfmathsetmacro{\Length}{3}
\pgfmathsetmacro{\Stretch}{2}
% \draw[-latex] (0,0,0) -- (\Length,0,0) node[below]{$x$};
% \draw[-latex] (0,0,0) -- (0,\Length,0) node[left]{$y$};
% \draw[-latex] (0,0,0) -- (0,0,\Length) node[left]{$z$};
\draw[red,very thick] plot[smooth,variable=\x,domain=0:720,samples=360]
({\Length*cos(\x-\Phase)},{\x*(\Stretch*\Length/360)},{-\Length*sin(\x-\Phase)});
\node[red,font=\Large\sffamily] at (-0.8*\Length,\Length,-1.7*\Length)
{Helix};
\draw (-1.2*\Length,0,-1.2*\Length) coordinate (lbf) --
(1.2*\Length,0,-1.2*\Length) coordinate (lbb) --
(1.2*\Length,0,1.2*\Length) coordinate (ltb) --
(-1.2*\Length,0,1.2*\Length) coordinate (ltf) -- cycle;
\foreach \X in {bf,bb,tb,tf}
{\draw (l\X) -- ++ (0,2*\Stretch*\Length,0) coordinate (m\X);}
\draw[very thick,fill=white,fill opacity=0.5] (mbf) -- (mbb) -- (mtb) -- (mtf) -- cycle;
\foreach \X in {bf,bb,tf}
{\draw[very thick] (m\X) -- ++ (0,2*\Stretch*\Length,0) coordinate (r\X);}
% middle
\path (mbb) node[below=3pt,font=\Large\sffamily] {Circle};
\draw[-latex] ($(mtf)+(0,0,0.4)$) -- ++ (0,0.5*\Length,0)
node[midway,above,sloped,font=\sffamily] {time};
\foreach \X in {1,...,5}
{\ifnum\X=3
\draw[very thick] ($(mbf)!{\X/6}!(mbb)$) -- ++ (0,3*\Stretch*\Length,0);
\draw[very thick] ($(mbf)!{\X/6}!(mtf)$) -- ++ (0,3*\Stretch*\Length,0);
\else
\draw ($(mbf)!{\X/6}!(mbb)$) -- ++ (0,3*\Stretch*\Length,0);
\draw ($(mbf)!{\X/6}!(mtf)$) -- ++ (0,3*\Stretch*\Length,0);
\fi}
\foreach \X [evaluate=\X as \Y using {int(mod(\X,5))}] in {1,...,18}
{
\ifnum\Y=0
\draw[very thick] ($(mbf)+(0,\X,0)$) -- ($(mbb)+(0,\X,0)$);
\draw[very thick] ($(mbf)+(0,\X,0)$) -- ($(mtf)+(0,\X,0)$);
\else
\draw ($(mbf)+(0,\X,0)$) -- ($(mbb)+(0,\X,0)$);
\draw ($(mbf)+(0,\X,0)$) -- ($(mtf)+(0,\X,0)$);
\fi
}
\draw[thick] plot[smooth,variable=\x,domain=0:360]
({\Length*cos(\x-\Phase)},2*\Stretch*\Length,{-\Length*sin(\x-\Phase)});
\foreach \X in {1,...,12}
{
\draw[thick] (0,2*\Stretch*\Length,0)
--
({\Length*cos(\X*(360/12))},2*\Stretch*\Length,{-\Length*sin(\X*(360/12))});
}
\draw[red,very thick] plot[smooth,variable=\x,domain=720:1440,samples=360] ({\Length*cos(\x-\Phase)},
{\x*(\Stretch*\Length/360)},{-\Length*sin(\x-\Phase)});
\draw[blue,very thick] plot[smooth,variable=\x,domain=720:1800,samples=360]
({\Length*cos(\x-\Phase)},{\x*(\Stretch*\Length/360)},-1.2*\Length);
\draw[blue,very thick] plot[smooth,variable=\x,domain=720:1800,samples=360]
(-1.2*\Length,{\x*(\Stretch*\Length/360)},{-\Length*sin(\x-\Phase)});
% right
\foreach \X in {bf,bb,tf}
{\draw[very thick] (r\X) -- ++ (0,\Stretch*\Length,0);}
\path (rbb) node[below=3pt,font=\Large\sffamily] {Cosine};
\path (rtf) node[above=3pt,font=\Large\sffamily] {Sine};
\path (mtb) -- ++ (0,2*\Stretch*\Length,0) coordinate (rtb);
\draw[very thick,fill=white,fill opacity=0.5] (rbf) -- (rbb) -- (rtb) -- (rtf) -- cycle;
\draw[thick,fill=white,fill opacity=0.5] plot[smooth,variable=\x,domain=0:360]
({\Length*cos(\x-\Phase)},4*\Stretch*\Length,{-\Length*sin(\x-\Phase)});
\foreach \X in {1,...,12}
{
\draw[thick] (0,4*\Stretch*\Length,0)
--
({\Length*cos(\X*(360/12))},4*\Stretch*\Length,{-\Length*sin(\X*(360/12))});
}
\end{tikzpicture}}
\end{document}