![tikz-3d/pgfplots:如何绘制/绘制弯曲时空?](https://linux22.com/image/429460/tikz-3d%2Fpgfplots%EF%BC%9A%E5%A6%82%E4%BD%95%E7%BB%98%E5%88%B6%2F%E7%BB%98%E5%88%B6%E5%BC%AF%E6%9B%B2%E6%97%B6%E7%A9%BA%EF%BC%9F.png)
由于我尝试为物理专业的学生写一篇关于张量的简短介绍,我提到了爱因斯坦的场方程(作为动机)。因此,我想创建一个弯曲时空的 tikzpicture/pgfplots。首先,我创建了一个 3d 图,它看起来很像最常见的弯曲时空图
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
unit vector ratio*=1 1 1,
hide axis = true,
x domain = -1.5:1.5,
zmin = -2.5,
zmax = 2.5
]
\addplot3 [
surf,
faceted color = lightgray,
fill = white,
line width = 0.1pt,
samples = 50] {-1.5*exp(-0.5*(x^2+y^2))};
\end{axis}
\end{tikzpicture}
\end{document}
这让我
但实际上,这并不是弯曲时空的最佳表示,因为这幅图只显示了一个方向的曲率(这里是沿着 z 轴)。更好的可视化应该是 像这样(YouTube 动画)或这。
我发现类似的东西\usepgfmodule{nonlineartransformations}
可能会有帮助,但是当谈到 tikz/pgfplots 时,我仍然是个初学者。
提前感谢您的所有回答!
答案1
两种可能性:
- 几乎纯钛钾Z one(只需要
perspective
的库3d view
):
\documentclass[tikz,border=1.618mm]{standalone}
\usetikzlibrary{perspective}
\begin{document}
\begin{tikzpicture}[3d view={120}{30},samples=51,domain=-2.5:2.5]
\foreach\i in {-2.5,-2.25,...,2.5}
{% curved spacetime
\draw[gray] plot (\x,\i,{2.5-0.5*exp(-0.75*(\x*\x+\i*\i))});
\draw[gray] plot (\i,\x,{2.5-0.5*exp(-0.75*(\x*\x+\i*\i))});
\draw[gray] plot (\x,{2.5-0.5*exp(-0.75*(\x*\x+\i*\i))},\i);
\draw[gray] plot (\i,{2.5-0.5*exp(-0.75*(\x*\x+\i*\i))},\x);
\draw[gray] plot ({2.5-0.5*exp(-0.75*(\x*\x+\i*\i))},\x,\i);
\draw[gray] plot ({2.5-0.5*exp(-0.75*(\x*\x+\i*\i))},\i,\x);
}% axes
\draw[thick,-latex] (2,0,0) -- (5,0,0) node[left] {$x$};
\draw[thick,-latex] (0,2,0) -- (0,5,0) node[right] {$y$};
\draw[thick,-latex] (0,0,2) -- (0,0,5) node[above] {$z$};
\end{tikzpicture}
\end{document}
- 还有一个
pgfplots
版本:
\documentclass[border=1.618mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[line width=0.1pt]
\begin{axis}
[
hide axis=true,
domain=-2.5:2.5,
zmin=-2.5,zmax=2.5,
samples=50,
z buffer=sort
]
\addplot3[surf,faceted color=lightgray,fill=white] {2.5-1.5*exp(-0.5*(x^2+y^2))};
\addplot3[surf,faceted color=lightgray,fill=white] ({2.5-1.5*exp(-0.5*(x^2+y^2))},x,y);
\addplot3[surf,faceted color=lightgray,fill=white] (x,{-2.5+1.5*exp(-0.5*(x^2+y^2))},y);
\end{axis}
\end{tikzpicture}
\end{document}