我是使用 tikz/pgfplots 创建图形的新手。它非常强大,但因此也很复杂。
我的具体案例是将单个圆环与圆弧段组合在一起。下图应该给人一种印象
我到目前为止所做的就是这个 MWE
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[thkline/.style={thick, blue, <-, >=stealth}]
\coordinate(O) at (-2.75,-1.35);
\coordinate(A) at (1.25,-0.35);
\begin{axis}[anchor=origin, xmax=15, ymax=15, zmax=6, axis lines = none,
colormap={red}{color=(lightgray) color=(lightgray)}]
\addplot3[domain=0:360,y domain=0:360, samples=25, surf, z buffer=sort]
(
{3 * sin(x)},
{(4 + 3 * cos(x)) * sin(y)},
{-(4 + 3 * cos(x)) * cos(y)});
\end{axis}
% \draw[thkline, rotate = 3] (O) arc (-90:60:3 and 1.5) node [below right] {$e^-$} ;
\draw[thkline, rotate = 0] (O) arc (-90:90:3 and 1.) node [below right] {$e^-$} ;
\end{tikzpicture}
\end{document}
我希望有专家能给我指明正确的方向。提前谢谢!
編輯我
根据下面给出的答案,我使用第一个解决方案重新编写了代码,并发现了一个相当有趣的问题,因为对象未对齐:
这种行为是否与 pgf 版本有关?由于我们使用\pgfplotsset{compat=1.16}
編輯 II
在添加到两个范围后,奇怪的偏移仍然存在\begin{scope}[canvas is xy plane at z=0,>=stealth, shift={(axis cs: 0,0,0)}]
。它似乎适用于顶线(注释为“加速度”)、圆环本身和第二个范围的一部分(带箭头的短弧):
答案1
欢迎!您已经很接近了。为了在 xy 平面上绘制内容,加载 Ti 可能是一个好主意钾Z 库 3d。
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{3d}
\begin{document}
\begin{tikzpicture}[thkline/.style={thick, blue, >=stealth},font=\sffamily]
\begin{axis}[anchor=origin, xmax=15, ymax=15, zmax=6, axis lines = none,
colormap={red}{color=(lightgray) color=(lightgray)},
clip=false]
%background stuff
\draw[ultra thick] (0,0,0) coordinate(O) -- (-25,0,0)
node[pos=2/3,above,sloped]{acceleration};
\begin{scope}[canvas is xy plane at z=0,>=stealth]
\draw[ultra thick,->] (0,0) -- (-25,0);
\draw[very thick,->] (0,30) -- (0,0);
\draw[->] (0,0) coordinate(O) -- (0,-7);
\draw[very thick] (0,0) arc(0:-30:50);
\end{scope}
% torus
\addplot3[domain=0:360,y domain=0:360, samples=25, surf, z buffer=sort,
opacity=0.6]
(
{3 * sin(x)},
{(4 + 3 * cos(x)) * sin(y)},
{-(4 + 3 * cos(x)) * cos(y)});
% foreground
\begin{scope}[canvas is xy plane at z=0,>=stealth]
\draw[->] (0,-7) -- (0,-30);
\draw[very thick,->,overlay] (-50,0)+(-8:50) arc(-8:-20:50);
\draw (0,-10) arc(-90:-180:10) node[midway,left]{$\mathsf{90}^\circ$};
\end{scope}
\end{axis}
\end{tikzpicture}
\end{document}
不幸的是 Ti 没有真正的 3D 引擎钾Z/pgfplots,所以必须按适当的顺序绘制事物。我在代码中指出了这一点。我估计有一个 8 的角度。
也可以使用 将箭头投影到平面上\pgflowlevelsynccm
。但是,pgfplots 执行的转换阻止我将其添加到轴内的范围。因此,可以从轴导出视图和缩放比例,并将范围添加到外部,将圆环后面的内容放在背景层上。
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{3d,backgrounds,calc}
\begin{document}
\begin{tikzpicture}[thkline/.style={thick, blue, >=stealth},font=\sffamily]
\begin{axis}[anchor=origin, xmax=15, ymax=15, zmax=6, axis lines = none,
colormap={red}{color=(lightgray) color=(lightgray)},
clip=false]
%background stuff
\draw[ultra thick] (0,0,0) coordinate(O) -- (-25,0,0)
node[pos=2/3,above,sloped]{acceleration};
\path let \p1=($(1,0,0)-(0,0,0)$),\p2=($(0,1,0)-(0,0,0)$),
\p3=($(0,0,1)-(0,0,0)$) in
\pgfextra{\xdef\myxx{\x1}\xdef\myxy{\y1}
\xdef\myyx{\x2}\xdef\myyy{\y2}
\xdef\myzx{\x3}\xdef\myzy{\y3}};
% torus
\addplot3[domain=0:360,y domain=0:360, samples=25, surf, z buffer=sort,
opacity=0.6]
(
{3 * sin(x)},
{(4 + 3 * cos(x)) * sin(y)},
{-(4 + 3 * cos(x)) * cos(y)});
% foreground
\begin{scope}[canvas is xy plane at z=0,>=stealth]
\draw (0,-10) arc(-90:-180:10) node[midway,left]{$\mathsf{90}^\circ$};
\end{scope}
\end{axis}
\begin{scope}[x={(\myxx,\myxy)},y={(\myyx,\myyy)},z={(\myzx,\myzy)},
canvas is xy plane at z=0,>=stealth,on background layer]
\pgflowlevelsynccm
\draw[line width=0.7cm,->] (0,0) -- (-10,0);
\draw[line width=0.5cm] (0,30) -- (0,0);
\draw[line width=0.5cm,->] (0,30) -- (0,20);
\draw[line width=0.1cm,->] (0,0) coordinate(O) -- (0,-7);
\draw[line width=0.5cm] (0,0) arc(0:-30:50);
\end{scope}
% foreground
\begin{scope}[x={(\myxx,\myxy)},y={(\myyx,\myyy)},z={(\myzx,\myzy)},
canvas is xy plane at z=0,>=stealth]
\pgflowlevelsynccm
\draw[line width=0.1cm,->] (0,-7) -- (0,-30);
\draw[line width=0.5cm,->,overlay] (-50,0)+(-8:50) arc(-8:-20:50);
\end{scope}
\end{tikzpicture}
\end{document}