绘制球体来表示黑洞

绘制球体来表示黑洞

谁能告诉我如何在球体内绘制一个球体?

我的意思是这样的:

在此处输入图片描述

另外,它说不同的地平线可以插入数学表达式吗?而且这些糟糕的颜色看起来也不是很专业。

任何帮助都非常感谢。

答案1

使用 TikZ 可以很容易地完成此操作,尽管您必须考虑输入命令的顺序。节点您可以使用数学模式:

代码

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{arrows}
\begin{document}

\begin{tikzpicture}
    \fill (-4,-4)   rectangle (4,4);
    \begin{scope}
        \clip (0:2.47) arc (0:90:2.47) to[out=225,in=100,looseness=1.2] (-1.1,-1.1) to[out=-10,in=225,looseness=1.2] (0:2.47);
        \shade[ball color=blue!30!gray!60!black,shading angle=180] (0,0) circle (2.5);
    \end{scope}
    \shade[ball color=green!70!gray] (0,0) circle (2);
    \begin{scope}
        \clip (0:1.95) arc (0:90:1.95) to[out=225,in=100] (-0.7,-0.7) to[out=-10,in=225] (0:1.95);
        \shade[ball color=green!30!gray!60!black,,shading angle=180] (0,0) circle (2);
    \end{scope}
    \begin{scope}
        \clip (0:2.45) arc (0:90:2.45) to[out=225,in=100,looseness=1.2] (-1.1,-1.1) to[out=-10,in=225,looseness=1.2] (0:2.45) -- (3,0) -- (3,-3) -- (-3,-3) -- (-3,3) -- (3,3) -- (3,0);
        \shade[ball color=blue!70!gray] (0,0) circle (2.5);
    \end{scope}
    \draw[stealth-,red] (0,0) -- ++(70:3) node[right] {$r=\int\limits_{0}^{2\pi}\sin(x)\ dx$};
    \draw[stealth-,green!70!black] (-0.7,1) -- ++(135:2) node[above] {$r=\frac{8^2+4^2}{8^2+6^2}$};
    \draw[stealth-,blue!90] (225:2) -- ++(225:1) node[below] {$r=\left(\frac{e^{\pi}}{\pi^e}\right)^{\sin(\pi)}$};
\end{tikzpicture}

\end{document}

输出

在此处输入图片描述


编辑1:

为了使球体看起来不那么有光泽,您可以定义自己的径向阴影,或修改球阴影(得益于尤里为了这个答案

代码

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{arrows}

\makeatletter
\pgfdeclareradialshading[tikz@ball]{ball}{\pgfqpoint{-10bp}{10bp}}%
{   color(0bp)=(tikz@ball!50!white);
    color(10bp)=(tikz@ball!75!white);
    color(15bp)=(tikz@ball);
    color(20bp)=(tikz@ball!75!black);
    color(30bp)=(tikz@ball!50!black)
}
\makeatother

\begin{document}

\begin{tikzpicture}
    \fill (-4,-4)   rectangle (4,4);
    \begin{scope}
        \clip (0:2.47) arc (0:90:2.47) to[out=225,in=100,looseness=1.2] (-1.1,-1.1) to[out=-10,in=225,looseness=1.2] (0:2.47);
        \shade[ball color=blue!30!gray!60!black,shading angle=180] (0,0) circle (2.5);
    \end{scope}
    \shade[ball color=green!70!gray] (0,0) circle (2);
    \begin{scope}
        \clip (0:1.95) arc (0:90:1.95) to[out=225,in=100] (-0.7,-0.7) to[out=-10,in=225] (0:1.95);
        \shade[ball color=green!30!gray!60!black,shading angle=180] (0,0) circle (2);
    \end{scope}
    \begin{scope}
        \clip (0:2.45) arc (0:90:2.45) to[out=225,in=100,looseness=1.2] (-1.1,-1.1) to[out=-10,in=225,looseness=1.2] (0:2.45) -- (3,0) -- (3,-3) -- (-3,-3) -- (-3,3) -- (3,3) -- (3,0);
        \shade[ball color=blue!70!gray,opacity=0.90] (0,0) circle (2.5);
    \end{scope}
    \draw[stealth-,red] (0,0) -- ++(70:3) node[right] {$r=\int\limits_{0}^{2\pi}\sin(x)\ dx$};
    \draw[stealth-,green!70!black] (-0.7,1) -- ++(135:2) node[above] {$r=\frac{8^2+4^2}{8^2+6^2}$};
    \draw[stealth-,blue!90] (225:2.2) -- ++(225:1) node[below] {$r=\left(\frac{e^{\pi}}{\pi^e}\right)^{\sin(\pi)}$};
\end{tikzpicture}

\end{document}

输出

在此处输入图片描述

答案2

精神上与 Tim Bombadil 更完整的答案非常相似,但使用的方法略有不同,因此绘制顺序更容易管理。它目前仅适用于沿相关轴的 90 度弧的“开口”,因为它们是用贝塞尔曲线近似的。

\documentclass[border=0cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,backgrounds}

% Constant taken from
%
% @article{riskus_2006,
%   author={Aleksas Ri\v{s}kus},
%   title={Approximation of a cubic bezier curve by circular arcs and vice versa},
%   year={2006},
%   journal={Information Technology and Control},
%   volume={35},
%   number={4},
%   pages={371--378}
% }
%
\def\k{0.55191496}

\tikzset{
    sphere color/.store in=\spherecolor,
    sphere scale/.store in=\spherescale,
    sphere color=blue,
    sphere scale=1,
    sphere/.style={
        ultra thick,
        line join=round,
        draw=#1!75!black,
        ball color=#1,
    },
    sphere inside/.style={
        shading angle=180,
        sphere=#1!25!gray!75!black
    }
}

\newenvironment{sphere}[1][]
    {
        \begin{scope}[x=(0:1cm), y=(90:1cm), z=(260:0.25cm), #1]
            \path [sphere inside=\spherecolor, scale=\spherescale] 
            circle [radius=1];
    }
    {
        \path let \n1={cos 10}, \n2={sin 10} in [sphere=\spherecolor, scale=\spherescale, even odd rule, opacity=0.5]
        circle [radius=1] 
        % Rotate 10 degrees around the y and x axes
        [x={(\n1, \n2^2, \n2*\n1)},
         y={(0, \n1, \n2)}, 
         z={(-\n2, -\n1*\n2, \n1^2)}] (0,1,0) 
                .. controls ++( 0, 0,\k) and ++(0,\k, 0) .. (0, 0, 1)
                .. controls ++(\k, 0, 0) and ++(0, 0,\k) .. (1, 0, 0) 
                .. controls ++(0, \k, 0) and ++(\k,0, 0) .. (0, 1, 0);
        \end{scope}
    }

\begin{document}

\begin{tikzpicture}[background rectangle/.style={fill=black}, show background rectangle]

\begin{sphere}[sphere scale=5, sphere color=blue]
    \begin{sphere}[sphere scale=4, sphere color=green]
        \begin{sphere}[sphere scale=3, sphere color=red]
            \begin{sphere}[sphere scale=2, sphere color=orange]
                \begin{sphere}[sphere scale=1, sphere color=yellow]

                \end{sphere}
            \end{sphere}
        \end{sphere}
    \end{sphere}
\end{sphere}

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案3

派克斯是用于 GNU/Linux 系统的面向批处理的实用程序集合,可创建具有输出格式(PSTricks、tikz 或 eepic 宏)或矢量(EPS 或 PDF)图像文件的数学上精确的图形、图表和电影,以便与 LaTeX 一起使用,不幸的是,在传统的 TeXLive/MiKTeX 发行版上不可用,但可以安装在 Linux 发行版(Ubuntu)上sudo apt-get install epix

如果您不介意使用外部图像文件,可以在 ePiX 中完成此绘图。(编译后的 PDF 中的坐标网格不如下面的 png 文件中的那么突出。)

输出

黑洞视界

代码

 /* -*-ePiX-*- */
    #include "epix.h"
    using namespace ePiX;

    double rad1(1), rad2(0.75);

    int N(60); // fineness of plot

    // parameter domains for southern/northern portions
    domain lower(P(0, 0, -M_PI_2), P(1, 2*M_PI, 0), mesh(N, N, 0.25*N));
    domain upper(P(0, M_PI_2, 0), P(1, 2*M_PI, M_PI_2), mesh(N, 0.75*N, 0.25*N));

    int main()
    {
      picture(P(-2,-2), P(2,2), "3 x 3in");

      begin();
      camera.at(P(4, 2, 2));

      fill();
      green(0.6);
      scenery S(sph, lower.slice1(rad2));
      S.add(sph, upper.slice1(rad2));

      // add slightly smaller sphere in brighter shade
      double scale(0.99);
      green(1.2);
      S.add(sph, lower.slice1(scale*rad2));
      S.add(sph, upper.slice1(scale*rad2));

      blue(0.8);
      S.add(sph, lower.slice1(rad1));
      S.add(sph, upper.slice1(rad1));

      blue(1.2);
      S.add(sph, lower.slice1(scale*rad1));
      S.add(sph, upper.slice1(scale*rad1));

      S.draw();

      // labels and guide lines
      black();
      P O(0, 0, 0),
        lbl1(sph(1.1*rad1, -M_PI_4, M_PI_4)),
        lbl2(sph(1.2*rad1, -M_PI/8, 5*M_PI/12)),
        lbl2b(sph(rad2, 0, 5*M_PI/12)),
        lbl3(sph(1.2*rad1, M_PI_2, M_PI/3));

      label(lbl1, P(-2, 2), "Outer horizon", tl);
      label(lbl2, P(-2, 2), "Inner horizon", t);
      label(lbl3, P(-2, 2), "Singularity", tr);

      pen(White(), 2);
      line(lbl2, lbl2b);
      line(lbl3, O);

      pen(Black(), 1);
      line(lbl2, lbl2b);
      line(lbl3, O);

      red();
      dot(P(0, 0, 0));

      tikz_format();
      end();
    }

编译方法

a)ePiX通过命令行运行:(需要安装 TeXLive 发行版以及ePiX转换为 pdf)

  • 将示例代码另存为sphereblack.xp并在命令行运行elaps --pdf sphereblack.xp直接生成sphereblack.pdf并单独包含在 LaTeX 中。

b)ePiX在.tex 文件中运行:

% pdflatex -shell-escape sphere.tex
\documentclass{article}
\immediate\write18{epix sphereblack.xp} % tikz macros due to tikz_format();
\usepackage{tikz}
\begin{document}
\input{sphereblack.eepic} % Input the tikz macros in sphereblack.eepic
\end{document}

有关详细信息,请参阅ePiX 手册

相关内容