如何在 tikz 图片中绘制交叉口?

如何在 tikz 图片中绘制交叉口?

我想用 tikz 绘制这幅图: 一个原子

这是我目前能够实现的目标:

\documentclass{standalone}
\usepackage{tikz}
\pagecolor{yellow}

\begin{document}

\color{orange!80!red}

\begin{tikzpicture}
    \clip (-0.5,-0.5) rectangle (.5,.5);
    
    \begin{scope}[xshift=4,yshift=12.4]
        \fill (0,0) circle (0.05);
    \end{scope}
    
    \begin{scope}[xshift=10.5,yshift=-8.5]
        \fill (0,0) circle (0.05);
    \end{scope}
    
    \begin{scope}[xshift=-11.5,yshift=-5.5]
        \fill (0,0) circle (0.05);
    \end{scope}
    
    \clip[xshift=4,yshift=12.4] (0,0) circle (0.06) [insert path ={(-2,-2) rectangle (2,2)}];
    \clip[xshift=10.5,yshift=-8.5] (0,0) circle (0.06) [insert path ={(-2,-2) rectangle (2,2)}];
    \clip[xshift=-11.5,yshift=-5.5] (0,0) circle (0.06) [insert path ={(-2,-2) rectangle (2,2)}];
    
    \begin{scope}[rotate=-70]
        \clip (-0.015,0.005) ellipse (0.17 and 0.46) [insert path ={(-0.5,-0.5) rectangle (.5,.5)}];
        \fill (0,0) ellipse (0.2 and 0.5);
    \end{scope}
    
    \begin{scope}[rotate=50]
        \clip (-0.015,0.005) ellipse (0.17 and 0.46) [insert path ={(-2,-2) rectangle (2,2)}];
        \fill (0,0) ellipse (0.2 and 0.5);
    \end{scope}
    
    \begin{scope}[rotate=-10]
        \clip (-0.015,0.005) ellipse (0.17 and 0.46) [insert path ={(-2,-2) rectangle (2,2)}];
        \fill (0,0) ellipse (0.2 and 0.5);
    \end{scope}
    
    \begin{scope}[xshift=-0.33,yshift=0.05]
        \fill (0,0) circle (0.08);
    \end{scope}

\end{tikzpicture}

\end{document}

我不知道如何绘制每个椭圆的交叉点。请注意,背景颜色尚未确定,可能不是是白色的,所以不能在每个椭圆后面画一个更宽的背景色椭圆。

我相信这可以通过多次使用来实现\clip,就像我在这里淹没的三个圆圈一样,但对于椭圆来说,它似乎更加棘手,我对此一无所知。

你有什么建议吗?

答案1

我会把圆圈和正确的颜色留给你。

\documentclass[tikz, border=0.01cm]{standalone}
\begin{document}

\begin{tikzpicture}
\newcommand{\bgd}{(-0.5,-0.5) rectangle (0.5,0.5)}
\newcommand{\smallEll}{(-0.015,0.005) ellipse (0.17 and 0.46)}
\newcommand{\smallerEll}{(-0.015,0.005) ellipse (0.16 and 0.45)}
\newcommand{\largeEll}{(0,0) ellipse (0.2 and 0.5)};
\newcommand{\largerEll}{(0,0) ellipse (0.21 and 0.51)};

%test bgd
\shade[clip] \bgd;

%red
\fill[red, rotate=-10, even odd rule] \smallEll \largeEll;
    
%green
\begin{scope}
  \clip[rotate=-10] \smallerEll;
  \fill[green, rotate=50, even odd rule] \smallEll \largeEll;
\end{scope}
\begin{scope}
  \clip[rotate=-10] \bgd \largerEll;
  \fill[green, rotate=50, even odd rule] \smallEll \largeEll;
\end{scope}
    
%blue
\begin{scope}
  \clip[rotate=-10] \smallerEll;
  \clip[rotate=50] \smallerEll;
  \fill[blue, rotate=-70, even odd rule] \smallEll \largeEll; 
\end{scope}
\begin{scope}
  \clip[rotate=-10] \smallerEll;
  \clip[rotate=50] \bgd \largerEll;
  \fill[blue, rotate=-70, even odd rule] \smallEll \largeEll; 
\end{scope}
\begin{scope}
  \clip[rotate=-10] \bgd \largerEll;
  \clip[rotate=50] \smallerEll;
  \fill[blue, rotate=-70, even odd rule] \smallEll \largeEll; 
\end{scope}
\begin{scope}
  \clip[rotate=-10] \bgd \largerEll;
  \clip[rotate=50] \bgd \largerEll;
  \fill[blue, rotate=-70, even odd rule] \smallEll \largeEll; 
\end{scope}
   
\end{tikzpicture}
\end{document}

带交叉点的红色、绿色和蓝色椭圆


编辑: 我刚刚发现,我可以在范围内使用剪辑even odd rule,从而一次性填充省略号。 - 使代码更简单:

\documentclass[tikz, border=0.01cm]{standalone}
\begin{document}

\begin{tikzpicture}[even odd rule]
\newcommand{\bgd}{(-0.5,-0.5) rectangle (0.5,0.5)}
\newcommand{\smallEll}{(-0.015,0.005) ellipse (0.17 and 0.46)}
\newcommand{\smallerEll}{(-0.015,0.005) ellipse (0.16 and 0.45)}
\newcommand{\largeEll}{(0,0) ellipse (0.2 and 0.5)};
\newcommand{\largerEll}{(0,0) ellipse (0.21 and 0.51)};

%test bgd
\shade[clip] \bgd;

%red
\fill[red, rotate=-10] \smallEll \largeEll;
    
%green
\clip[rotate=-10] \smallerEll \largerEll \bgd;
\fill[green, rotate=50] \smallEll \largeEll;
   
%blue
\clip[rotate=50] \smallerEll \largerEll \bgd;
\fill[blue, rotate=-70] \smallEll \largeEll; 

\end{tikzpicture}
\end{document}

答案2

这是完成的代码(感谢@hpekristiansen):

\documentclass[tikz]{standalone}

\begin{document}

\color{orange}

\begin{tikzpicture}[even odd rule]
    \newcommand{\bgd}{(-0.5,-0.5) rectangle (0.5,0.5)}
    \newcommand{\smallEll}{(-0.015,0.005) ellipse (0.17 and 0.46)}
    \newcommand{\smallerEll}{(-0.015,0.005) ellipse (0.16 and 0.45)}
    \newcommand{\largeEll}{(0,0) ellipse (0.2 and 0.5)};
    \newcommand{\largerEll}{(0,0) ellipse (0.21 and 0.51)};
    
    %test bgd
    \clip \bgd;
    
    \begin{scope}[xshift=4,yshift=12.4]
        \fill (0,0) circle (0.05);
    \end{scope}
    
    \begin{scope}[xshift=10.5,yshift=-8.5]
        \fill (0,0) circle (0.05);
    \end{scope}
    
    \begin{scope}[xshift=-11.5,yshift=-5.5]
        \fill (0,0) circle (0.05);
    \end{scope}
    
    \clip[xshift=4,yshift=12.4] (0,0) circle (0.06) [insert path ={(-2,-2) rectangle (2,2)}];
    \clip[xshift=10.5,yshift=-8.5] (0,0) circle (0.06) [insert path ={(-2,-2) rectangle (2,2)}];
    \clip[xshift=-11.5,yshift=-5.5] (0,0) circle (0.06) [insert path ={(-2,-2) rectangle (2,2)}];
        
    \fill[rotate=-10] \smallEll \largeEll;
        
    \clip[rotate=-10] \smallerEll \largerEll \bgd;
    \fill[rotate=50] \smallEll \largeEll;
       
    \clip[rotate=50] \smallerEll \largerEll \bgd;
    \fill[rotate=-70] \smallEll \largeEll; 
    
    \fill (-0.02,0) circle (0.08);
\end{tikzpicture}

\end{document}

输出如下:(感谢@projetmbc 提供这张图片)

在此处输入图片描述

相关内容