Chemfig:3d 分子

Chemfig:3d 分子

我想用 chemfig 绘制分子。找不到任何连接核心。有什么想法吗?

在此处输入图片描述

答案1

也许这不是你喜欢的答案,但我不知道一种优雅的方式来将chemfig图片置于 3d 投影中,既不嵌套tikzpictures 也不使用\saveboxes,在这种情况下,你将无法再从外部访问节点。所以我建议用基本 Ti 绘制六边形tikz-3dplotZ 方法,以及用于3d进行投影的库。我感谢 andselisk 的评论,它为我澄清了一些我不知道的事情。我不是化学家,所以我不知道点群D_{3h}是什么,尽管像任何土拨鼠一样,我知道点群D_3是什么。无论如何,这是一个更新,非常感谢 andselisk。(根据要求,我在代码中添加了一些解释。这个想法是使用 3d 坐标并让 TiZ 进行投影。该tikz-3dplot包允许您选择一个由两个角度定义的视图,并且该3d库允许您在 3d 坐标中的平面上绘制事物。所以我们将在 3 个平面上绘制 3 个六边形,这些六边形彼此旋转 120 度。然后我们将在 3d 中连接它们。我在代码中添加了一些注释。)

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{shapes.geometric,3d,calc}
\begin{document}
\tdplotsetmaincoords{70}{20} % sets the view angles, see the tik-3dplot manual for details 
\begin{tikzpicture}[tdplot_main_coords,% use the above view
hexa/.style={regular polygon, % just a hexagon shape; the corners are anchors
regular polygon sides=6,minimum size=3cm,draw}] 
\foreach \Z in {1,2,3} % \Z labels three planes
{\tdplotsetrotatedcoords{0}{\Z*120}{0}
\begin{scope}[tdplot_rotated_coords,transform shape,
canvas is yz plane at x=0] % switch to a rotated plane
  \node[hexa] (h\Z) at (0,{3*sin(60)}) {}; % draw a hexagon in the plane
  \foreach \X [evaluate=\X as \Y using {int(mod(\X+1,6))}] in {2,4,6} 
  {\draw ($(h\Z.corner \X)!0.2!(h\Z.center)$) -- 
  ($(h\Z.corner \Y)!0.2!(h\Z.center)$);} % draw thick hexagon edges
  \draw[ultra thick] (h\Z.corner 2) -- (h\Z.corner 3) -- (h\Z.corner 4);
% uncomment these out to see where the rotated coordinate axes point to
% \begin{scope}[blue]
% \draw[-latex] (0,0,0) -- (2,0,0) node[pos=1.1]{$x'$};
% \draw[-latex] (0,0,0) -- (0,2,0) node[pos=1.1]{$y'$};
% \draw[-latex] (0,0,0) -- (0,0,2) node[pos=1.1]{$z'$};
% \end{scope}
 \end{scope}
\draw (h\Z.corner 5) -- (0,{3*sin(60)/2},0); % thin connecting the 3 hexagons in the back
\path (h\Z.corner 4) -- (0,{-3*sin(60)/2},0) coordinate[midway](aux);
\draw[ultra thick] (h\Z.corner 4) -- (aux);
\draw[double distance=1.6pt,ultra thick,white,double=black] (aux) --
(0,{-3*sin(60)/2},0); % draw the thick connections to the point between the
% three hexagons in the foreground (with "gaps" around the path
}
% uncomment these out to see where the main coordinate axes point to
% \draw[-latex] (0,0,0) -- (3,0,0) node[pos=1.1]{$x$};
% \draw[-latex] (0,0,0) -- (0,3,0) node[pos=1.1]{$y$};
% \draw[-latex] (0,0,0) -- (0,0,3) node[pos=1.1]{$z$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

这样做的好处是可以随意改变视角。

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{shapes.geometric,3d,calc}
\begin{document}
\foreach \ZZ in {5,15,...,355}
{\tdplotsetmaincoords{70+20*sin(\ZZ)}{\ZZ}
\pgfmathtruncatemacro{\itest}{sign(cos(\ZZ))}
\begin{tikzpicture}[tdplot_main_coords,hexa/.style={regular polygon,regular polygon sides=6,
minimum size=3cm,draw}]
 \path[tdplot_screen_coords,use as bounding box] (-5,-5) rectangle (5,5);
 \foreach \Z in {1,2,3}
 {\tdplotsetrotatedcoords{0}{\Z*120}{0}
 \begin{scope}[tdplot_rotated_coords,transform shape,canvas is yz plane at x=0]
   \node[hexa] (h\Z) at (0,{3*sin(60)}) {};
   \foreach \X [evaluate=\X as \Y using {int(mod(\X+1,6))}] in {2,4,6}
   {\draw ($(h\Z.corner \X)!0.2!(h\Z.center)$) -- ($(h\Z.corner \Y)!0.2!(h\Z.center)$);}
   \ifnum\itest=1
    \draw[ultra thick] (h\Z.corner 2) -- (h\Z.corner 3) -- (h\Z.corner 4);
   \else
    \draw[ultra thick] (h\Z.corner 1) -- (h\Z.corner 6) -- (h\Z.corner 5);
   \fi  
  \end{scope}
  \ifnum\itest=1
   \path (h\Z.corner 4) -- (0,{-3*sin(60)/2},0) coordinate[midway](aux);
   \draw[ultra thick] (h\Z.corner 4) -- (aux);
   \draw[double distance=1.6pt,ultra thick,white,double=black] (aux) --
   (0,{-3*sin(60)/2},0);
   \draw (h\Z.corner 5) -- (0,{3*sin(60)/2},0);
  \else
   \path (h\Z.corner 5) -- (0,{3*sin(60)/2},0) coordinate[midway](aux);
   \draw[ultra thick] (h\Z.corner 5) -- (aux);
   \draw[double distance=1.6pt,ultra thick,white,double=black] (aux) --
   (0,{3*sin(60)/2},0);
   \draw (h\Z.corner 4) -- (0,{-3*sin(60)/2},0);
  \fi 
 }
\end{tikzpicture}}
\end{document}

在此处输入图片描述

我一直觉得《星球大战》中的一些宇宙飞船是受到分子的启发。这也解释了为什么它们可以在真空中产生声波。;-)

相关内容