在 tikz 3D 中将多个画布层居中

在 tikz 3D 中将多个画布层居中

因此,我试图精确地重新创建所附图像。但对于上方的红色环,我似乎无法将其很好地居中。我尝试了多种修改,但它就是不想像黑色虚线环那样居中。请帮忙。 在此处输入图片描述

梅威瑟:

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,positioning,decorations.pathreplacing,calligraphy,bending}
\usepackage{tikzsymbols}
\usepackage{tikz-3dplot}

\begin{document}
\tdplotsetmaincoords{70}{112}
\begin{tikzpicture}[tdplot_main_coords,line cap=round,>=stealth,scale=0.75]
\begin{scope}[rotate=9]
\draw[dashed,thick,canvas is xy plane at z=0] circle[radius=2.75cm];
\end{scope}
\begin{scope}[roll=9]
\draw[dashed,thick,red,canvas is xy plane at z=2] circle[radius=1.75cm];
\end{scope}
\draw[-Latex] (0,0,0) coordinate (O) -- (7,0,0) node[pos=1.2] {$x$}; 
\draw[-Latex,rotate around={8:(O)}] (O) -- (0,4,0) node[pos=1.1] {$y$};
\draw[-Latex] (O) -- (0,0,4) node[pos=1.1] {$z$};
\end{tikzpicture}
\end{document}

答案1

我认为你的代码中的主要问题是

\begin{scope}[roll=9]

这会产生错误,无法编译。我想你会rotate喜欢另一种方式scope

\begin{scope}[rotate=9]

如果您能以某种方式获得代码的汇编(我想在 Overleaf 中,但我不知道这是否可行),黑色圆圈会旋转,但红色圆圈不会。它们居中,但围绕 z 轴的旋转不同,我认为这就是您想要解决的问题。

无论如何,如果您选择 3D 视图,则无需旋转圆圈。为此,您可以定义轴(就像我做的那样)或使用tikz-3dplot包,perspectiveTiZ 库,...

这是一个可自定义的代码,几乎没有包和库。我只使用3d库作为选项

canvas is xy plane at z=...

arrows.meta但如果您需要更多箭头样式,我想您也会想要将其包括在内。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3d}  % for "canvas is..." options
\tikzset{my circle/.style={dashed,thick,canvas is xy plane at z=#1}}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,
                    x={(-0.4cm,-0.4cm)}, y={(1cm,0cm)},z={(0cm,1cm)}] % <--- 3d axes
% dimensions
\def\br{2.5}   % big radius
\def\lr{1.75}  % little radius
\def\ch{2}     % circles height
\def\na{8}     % number of arrows
\pgfmathsetmacro\aa{360/\na} % angle between arrows
% origin
\coordinate (O) at (0,0,0);
% axes
\draw[-latex] (O)      -- (6,0,0) node[below] {$x$}; 
\draw[-latex] (O)      -- (0,4,0) node[right] {$y$};
\draw[-latex] (0,0,-4) -- (0,0,4) node[above] {$z$};
% circles
\draw[my circle=-\ch,blue] circle[radius=\lr];
\draw[my circle= 0]        circle[radius=\br];
\draw[my circle= \ch,red]  circle[radius=\lr];
% arrows
\foreach\i in {1,...,\na}
{
  \draw[red ,thick,-latex] (O) -- ({\lr*cos(\i*\aa)},{\lr*sin(\i*\aa)}, \ch);
  \draw[blue,thick,-latex] (O) -- ({\lr*cos(\i*\aa)},{\lr*sin(\i*\aa)},-\ch);
}
\draw[thick,-latex]  (O) -- (0,\br,0) node[midway,above] {$\mathbf{L}$};
% aux lines and \hbar
\foreach\i in {-1,1}
  \draw[gray,dashed] (0,\lr,\i*\ch) --++ (0,-\lr,0) node[black,left] {$\ifnum\i<0-\fi\hbar$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容