这是我第一次真正回答 LaTeX 问题,所以我希望我能答对。如果没有,请告诉我。我四处寻找,但找不到我的问题的答案,在 stackexchange 上找不到,在 tikz-3dplot 手册中也找不到。
问题陈述
我正在使用一些 for 循环来构建一个菱形格子,我想用黑色和白色球体为其站点涂上双色。在下面的 MWE 中,我绘制了一个站点,4 个最近邻居链接源自该站点。在这个例子中,我使用了一个阴影圆圈,使站点看起来像一个球。在这个例子中,你会看到圆盘覆盖了下面的所有内容。我想要做的是将圆盘变成一个真正的球体,并查看矢量在球体的哪个点“出来”。这背后的想法是为了更好地看到 3d 方向。
因此,确切地说,tikz-3dplot 中是否存在“圆圈”的类似物,如下所示:
\draw (0,0,0) sphere [radius = .2 cm]; ?
如果没有,有人可以给我指明正确的方向吗?
请注意,手动将矢量从假定球体的表面而不是站点位置(我示例中的原点)开始是可行的,但由于我生成了约 30 个站点的晶格,因此这将非常繁琐。此外,设置不透明度以使矢量透过仍然看起来不太有空间感。
如果有人想尝试或想获得启发,我还在下面放了绘制格子的完整代码。直接位于 MWE 的输出(左)和完整代码(右)下方(我将它们放在一页上)。在 MWE 中可以看到线条永远不会与圆圈重叠。
图片
MWE 绘制带有债券的单一站点
\documentclass[a4paper]{standalone}
\usepackage{tikz,tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{40} %{theta in [0,pi]}{phi in [0,2pi]}
\begin{tikzpicture}[tdplot_main_coords, scale=2]
% defining vectors s1,s2,s3,s0
\tdplotsetcoord{s1}{1}{60}{-90}
\tdplotsetcoord{s2}{1}{60}{90}
\tdplotsetcoord{s3}{1}{120}{180}
\tdplotsetcoord{s0}{1}{120}{0}
% setting origin to be called 'O'
\coordinate (O) at (0,0,0);
% drawing axes
\draw[thick,red,opacity=.5,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};
\draw[thick,red,opacity=.5,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$};
\draw[thick,red,opacity=.5,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};
\draw[thick,red,opacity=.25] (0,0,0) -- (-2,0,0);
\draw[thick,red,opacity=.25] (0,0,0) -- (0,-2,0);
\draw[thick,red,opacity=.25] (0,0,0) -- (0,0,-2);
% drawing vectors
\draw [very thick, blue,->] (O) -- ++(s1) node[anchor=south east]{$s_1$};
\draw [very thick, blue,->] (O) -- ++(s2) node[anchor=south west]{$s_2$};
\draw [very thick, blue,->] (O) -- ++(s3) node[anchor=north]{$s_3$};
\draw [very thick, blue,->] (O) -- ++(s0) node[anchor=north east]{$s_0$};
% dotted projection lines on the x-y plane
\draw [blue, dotted] (s1) -- (s1xy);
\draw [blue, dotted] (s2) -- (s2xy);
\draw [blue, dotted] (s3) -- (s3xy);
\draw [blue, dotted] (s0) -- (s0xy);
% drawing 'sphere' on the origin O
\shade[ball color=black!30!white] (0,0,0) circle (.2cm);
\end{tikzpicture}
\end{document}
II 整个文档,构建格子
\documentclass[a4paper]{standalone}
\usepackage{tikz,tikz-3dplot}
\begin{document}
\begin{center}
\tdplotsetmaincoords{60}{100} %60 130
\begin{tikzpicture}[tdplot_main_coords, scale=1]
% storing values of square roots
\pgfmathsetmacro{\N}{.85};
\pgfmathsetmacro{\Nz}{1};%{2/sqrt(3)};
% setting origin and axes
\coordinate (O) at (0,0,0);
\draw[thick,red,opacity=.5,->] (0,0,0) -- (3,0,0) node[anchor=north east]{$x$};
\draw[thick,red,opacity=.5,->] (0,0,0) -- (0,3,0) node[anchor=north west]{$y$};
\draw[thick,red,opacity=.5,->] (0,0,0) -- (0,0,3) node[anchor=south]{$z$};
\draw[thick,red,opacity=.25] (0,0,0) -- (-3,0,0);
\draw[thick,red,opacity=.25] (0,0,0) -- (0,-3,0);
\draw[thick,red,opacity=.25] (0,0,0) -- (0,0,-3);
% defining s1,s2,s3,s0
\tdplotsetcoord{s1}{1}{60}{-90}
\tdplotsetcoord{s2}{1}{60}{90}
\tdplotsetcoord{s3}{1}{120}{180}
\tdplotsetcoord{s0}{1}{120}{0}
% drawing axes and vectors below
\coordinate (O2) at (0,0,-10);
\draw[thick,red,opacity=.5,->] (0,0,-10) -- (3,0,-10) node[anchor=north east]{$x$};
\draw[thick,red,opacity=.5,->] (0,0,-10) -- (0,3,-10) node[anchor=north west]{$y$};
\draw[thick,red,opacity=.5,->] (0,0,-10) -- (0,0,-7) node[anchor=south]{$z$};
\draw[thick,red,opacity=.25] (0,0,-10) -- (-3,0,-10);
\draw[thick,red,opacity=.25] (0,0,-10) -- (0,-3,-10);
\draw[thick,red,opacity=.25] (0,0,-10) -- (0,0,-13);
\draw [very thick, blue,->] (O2) -- ++(s1) node[anchor=south east]{$s_1$};
\draw [very thick, blue,->] (O2) -- ++(s2) node[anchor=south west]{$s_2$};
\draw [very thick, blue,->] (O2) -- ++(s3) node[anchor=south west]{$s_3$};
\draw [very thick, blue,->] (O2) -- ++(s0) node[anchor=north east]{$s_0$};
% drawing lattice
\foreach \a in {0,1.7}%,3.4}
\foreach \b in {0,1.5}
\foreach \c in {0,1.7}{
\draw [thick] (\a, \c, \b) -- ++(s1) node (pos1) {};
\draw [thick] (\a, \c, \b) -- ++(s2) node (pos2) {};
\draw [thick] (\a, \c, \b) -- ++(s3) node (pos3) {};
\draw [thick] (\a, \c, \b) -- ++(s0) node (pos4) {};
\draw [thick] (\a+ \N, \c+\N, \b +\Nz) -- ++(s1) node (pos5) {};
\draw [thick] (\a+ \N, \c+\N, \b+\Nz) -- ++(s2) node (pos6) {};
\draw [thick] (\a+\N, \c+\N, \b+\Nz) -- ++(s3) node (pos7) {};
\draw [thick] (\a+ \N, \c+\N, \b+\Nz) -- ++(s0) node (pos8) {};
% drawing sites
\shade[ball color=black!10!white] (pos1) circle (.1cm);
\shade[ball color=black!10!white] (pos2) circle (.1cm);
\shade[ball color=black!10!white] (pos3) circle (.1cm);
\shade[ball color=black!10!white] (pos4) circle (.1cm);
\shade[ball color=black!10!white] (pos5) circle (.1cm);
\shade[ball color=black!10!white] (pos6) circle (.1cm);
\shade[ball color=black!10!white] (pos7) circle (.1cm);
\shade[ball color=black!10!white] (pos8) circle (.1cm);
\shade[ball color=white!10!black] (\a,\c,\b) circle (.1cm);
\shade[ball color=white!10!black] (\a+\N,\c+\N,\b+\Nz) circle (.1cm);
}
\end{tikzpicture}
\end{center}
\end{document}
答案1
最大的问题是你需要按顺序从后往前绘制所有内容,而你的循环设置并不完全符合这一要求。此外,有些球体几乎直接位于其他球体的后面,这多少有点让人困惑。
无论如何,在循环中可以很容易地在球体顶部绘制线条。
\documentclass[a4paper]{standalone}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{intersections,calc}
\begin{document}
\tdplotsetmaincoords{60}{100} %60 130
\begin{tikzpicture}[tdplot_main_coords, scale=1]
% storing values of square roots
\pgfmathsetmacro{\N}{.85};
\pgfmathsetmacro{\Nz}{1};%{2/sqrt(3)};
% setting origin and axes
\coordinate (O) at (0,0,0);
\draw[thick,red,opacity=.5,->] (0,0,0) -- (3,0,0) node[anchor=north east]{$x$};
\draw[thick,red,opacity=.5,->] (0,0,0) -- (0,3,0) node[anchor=north west]{$y$};
\draw[thick,red,opacity=.5,->] (0,0,0) -- (0,0,3) node[anchor=south]{$z$};
\draw[thick,red,opacity=.25] (0,0,0) -- (-3,0,0);
\draw[thick,red,opacity=.25] (0,0,0) -- (0,-3,0);
\draw[thick,red,opacity=.25] (0,0,0) -- (0,0,-3);
% defining s1,s2,s3,s0
\tdplotsetcoord{s1}{1}{60}{-90}
\tdplotsetcoord{s2}{1}{60}{90}
\tdplotsetcoord{s3}{1}{120}{180}
\tdplotsetcoord{s0}{1}{120}{0}
% sphere offsets
\tdplotsetcoord{v1}{-.1}{60}{-90}
\tdplotsetcoord{v2}{-.1}{60}{90}
\tdplotsetcoord{v3}{-.1}{120}{180}
\tdplotsetcoord{v0}{-.1}{120}{0}
% drawing axes and vectors below
\coordinate (O2) at (0,0,-10);
\draw[thick,red,opacity=.5,->] (0,0,-10) -- (3,0,-10) node[anchor=north east]{$x$};
\draw[thick,red,opacity=.5,->] (0,0,-10) -- (0,3,-10) node[anchor=north west]{$y$};
\draw[thick,red,opacity=.5,->] (0,0,-10) -- (0,0,-7) node[anchor=south]{$z$};
\draw[thick,red,opacity=.25] (0,0,-10) -- (-3,0,-10);
\draw[thick,red,opacity=.25] (0,0,-10) -- (0,-3,-10);
\draw[thick,red,opacity=.25] (0,0,-10) -- (0,0,-13);
\draw [very thick, blue,->] (O2) -- ++(s1) node[anchor=south east]{$s_1$};
\draw [very thick, blue,->] (O2) -- ++(s2) node[anchor=south west]{$s_2$};
\draw [very thick, blue,->] (O2) -- ++(s3) node[anchor=south west]{$s_3$};
\draw [very thick, blue,->] (O2) -- ++(s0) node[anchor=north east]{$s_0$};
% drawing lattice
\foreach \a in {0,1.7}%,3.4}
\foreach \b in {0,1.5}
\foreach \c in {0,1.7}{
\draw [thick] (\a, \c, \b) -- ++(s1) coordinate (pos1);
\draw [thick] (\a, \c, \b) -- ++(s2) coordinate (pos2);
\draw [thick] (\a, \c, \b) -- ++(s3) coordinate (pos3);
\draw [thick] (\a, \c, \b) -- ++(s0) coordinate (pos4);
\draw [thick] (\a+ \N, \c+\N, \b+\Nz) -- ++(s1) coordinate (pos5);
\draw [thick] (\a+ \N, \c+\N, \b+\Nz) -- ++(s2) coordinate (pos6);
\draw [thick] (\a+\N, \c+\N, \b+\Nz) -- ++(s3) coordinate (pos7);
\draw [thick] (\a+ \N, \c+\N, \b+\Nz) -- ++(s0) coordinate (pos8);
% drawing sites
\shade[ball color=black!10!white] (pos1) circle (.1cm);
\shade[ball color=black!10!white] (pos2) circle (.1cm);
\shade[ball color=black!10!white] (pos3) circle (.1cm);
\shade[ball color=black!10!white] (pos4) circle (.1cm);
\shade[ball color=black!10!white] (pos5) circle (.1cm);
\shade[ball color=black!10!white] (pos6) circle (.1cm);
\shade[ball color=black!10!white] (pos7) circle (.1cm);
\shade[ball color=black!10!white] (pos8) circle (.1cm);
\shade[ball color=white!10!black] (\a,\c,\b) circle (.1cm);
\shade[ball color=white!10!black] (\a+\N,\c+\N,\b+\Nz) circle (.1cm);
% redraw stub lines
\draw [thick,line cap=round] ($(pos1)+(v1)$) -- ++(v1);
\draw [thick,line cap=round] ($(pos2)+(v2)$) -- ++(v2);
%\draw [thick,line cap=round] ($(pos3)+(v3)$) -- ++(v3);
\draw [thick,line cap=round] ($(pos4)+(v0)$) -- ++(v0);
\draw [thick,line cap=round] ($(pos5)+(v1)$) -- ++(v1);
\draw [thick,line cap=round] ($(pos6)+(v2)$) -- ++(v2);
%\draw [red,thick,line cap=round] ($(pos7)+(v3)$) -- ++(v3);
\draw [thick,line cap=round] ($(pos8)+(v0)$) -- ++(v0);
}
\end{tikzpicture}
\end{document}