Tikz 3D - 洋葱层

Tikz 3D - 洋葱层

我还不熟悉 TikZ 中的 3D 图表,我想画一些类似附图的东西。有人有什么有用的提示吗?

恒星的洋葱层结构

答案1

好的,我将在 2D 中尝试一下,只是为了让你开始。

\documentclass[border=10pt]{standalone}
\usepackage{tikz}

\begin{document}
    \pagecolor{black}
    
    \definecolor{col1}{RGB}{255,255,153}
    \definecolor{col2}{RGB}{153,51,0}
    \definecolor{col3}{RGB}{209,209,224}
    \definecolor{col4}{RGB}{0,230,115}
    \definecolor{col5}{RGB}{204,0,204}
    \definecolor{col6}{RGB}{255,204,204}
    \definecolor{col7}{RGB}{0,153,254}
    \definecolor{col8}{RGB}{255,80,80}
    
    \begin{tikzpicture}
        \coordinate (C) at (0,0);
        
        \fill[outer color=black,inner color=col1] (C) circle (7 cm);
        \fill[ball color=col1,shading=ball] (C) circle (5 cm);
        \begin{scope}
            \clip (0,-5) rectangle (5,5);
            \foreach \r [count=\i from 1] in {5,4.8,4.6,3,2.5,2.2,1.8,1.6}
                {
                \fill[outer color=col\i,inner color=col\i!70!black] (C) circle (\r cm);
                }
        \end{scope}
        
        \begin{scope}
            \clip (0,-5) rectangle (-5,5);
            \foreach \r [count=\i from 1] in {5,4.8,4.6,3,2.5,2.2,1.8,1.6}
                {
                \filldraw[col\i!70!black] (C) ellipse (0.3*\r cm and \r cm);
                }
        \end{scope}
        
        \begin{scope}
            \clip (90:1.6) arc (90:270:0.3*1.6 cm and 1.6 cm) arc (-90:90:1.6);
            \filldraw[ball color=col8,shading=ball] (C) circle (1.6 cm);
        \end{scope}
    \end{tikzpicture}
\end{document}

看看这颗星星

编辑:我编辑了脚本以消除冗余和不适当的类声明,最重要的是,让您一次性定义所有切片半径。我尝试在每个切片中添加一些阴影,但目前还不起作用(除了在单独的代码行中编写每个切片,这让我很失望)。如果我找到正确的方法,我会稍后告诉您。

\documentclass[tikz,border=10pt]{standalone}

\begin{document}
    \pagecolor{black}
    
    \definecolor{col1}{RGB}{255,255,153}
    \definecolor{col2}{RGB}{153,51,0}
    \definecolor{col3}{RGB}{209,209,224}
    \definecolor{col4}{RGB}{0,230,115}
    \definecolor{col5}{RGB}{204,0,204}
    \definecolor{col6}{RGB}{255,204,204}
    \definecolor{col7}{RGB}{0,153,254}
    \definecolor{col8}{RGB}{255,102,0}
    
    \begin{tikzpicture}
        \coordinate (C) at (0,0);
        
        \def\a{5}   \def\b{4.8}  \def\c{4.6} \def\d{3}
        \def\e{2.2} \def\f{1.8}  \def\g{1}   \def\h{0.8}
        
        \fill[outer color=black,inner color=col1] (C) circle (6.5 cm);
        \fill[ball color=col1,shading=ball] (C) circle (5 cm);

        \begin{scope}
            \clip (0,-5) rectangle (5,5);
            \foreach \r [count=\i] in {\a,\b,\c,\d,\e,\f,\g,\h}
                {
                \fill[outer color=col\i,inner color=col\i!70!black] (C) circle (\r cm);
                }
        \end{scope}
        
        \begin{scope}
            \clip (0,-5) rectangle (-5,5);
            \foreach \r [count=\i] in {\a,\b,\c,\d,\e,\f,\g,\h}
                {
                \fill[col\i!70!black] (C) ellipse (0.3*\r cm and \r cm);
                }
        \end{scope}
        
        \begin{scope}
            \clip (90:\h) arc (90:270:0.3*\h cm and \h cm) arc (-90:90:\h);
            \fill[ball color=col8,shading=ball] (C) circle (\h cm);
        \end{scope}

    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容