在球面上绘制函数

在球面上绘制函数

在一篇论文中,我有一类函数年代1年代2取决于实际参数>0,我想用曲线来表示球体上的一些曲线,以说明它们的行为变为 0,但我从未使用过 TikZ 或其他任何东西,所以我不知道该怎么做。

答案1

我从解决这个问题中学到了很多东西。所以谢谢你的提问!这是我为 想出的近似 MWE pgfplotset

\PassOptionsToPackage{svgnames}{xcolor}
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage{mathtools}
\usepackage[Symbolsmallscale]{upgreek}
\usepackage{textcomp}
\usepackage{pgfplots}

\pgfplotsset{width=\textwidth,compat=1.12}
\pgfplotsset{colormap={ends}{gray(0cm)=(0.875) gray(1cm)=(0.125) gray(2cm)=(0.875)}}

\DeclareRobustCommand\degree{\ensuremath{^\circ}}

\begin{document}

Here's a MWE.  Let's use as our example the parameterized path that we would use to fly from the North Pole, facing Greenwich, to the South Pole, circumnavigating the globe \(t\) times clockwise.  For convenience, we'll use spherical coordinates \( (r,\theta,\phi) \) and use as our units radians and the Earth's radius, so the North Pole is at \( (1,\theta,0) \) and the South pole at \( (1,\theta,\uppi) \).  Each clockwise trip around the Earth is \(2 \uppi\) radians, and we make \(t\) of them.  Parameterizing the path in \( u \in [0,1] \):

\[ r = 1 \qquad \theta = 2\uppi t u \qquad \phi = \uppi u \]

Converting to Cartesian coordinates:

\begin{align*}
x &=& r \cos \theta \sin \phi &=& \cos 2\uppi t u \cdot \sin \uppi u \\
y &=& r \sin \theta \sin \phi &=& \sin 2\uppi t u \cdot \sin \uppi u \\
z &=& r \cos \phi &=& \cos \uppi u
\end{align*}

Here are some graphs of these parametric functions with \texttt{pgfplotset}.  The case where \(t=0.5\) is in green, \(t=1\) in blue and \(t=2\) in red.  These two plots are rotated \(90\degree\) from each other:

\begin{tikzpicture}
\begin{axis}[view={30}{30},
             xmin=-1, xmax=1, ymin=-1, ymax=1,
             xlabel=$x$, ylabel=$y$, zlabel=$z$,
             unit vector ratio = 1 1 1
            ]
  \addplot3[blue,line width=1pt,variable=\u,domain=0:1,samples=45]( {cos(360*1*u)*sin(180*u))}, {sin(360*1*u)*sin(180*u)}, {cos(180*u)} );
  \addplot3[red,line width=1pt,variable=\u,domain=0:1,samples=45]( {cos(360*2*u)*sin(180*u))}, {sin(360*2*u)*sin(180*u)}, {cos(180*u)} );
  \addplot3[green,line width=1pt,variable=\u,domain=0:1,samples=45]( {cos(360*0.5*u)*sin(180*u))}, {sin(360*0.5*u)*sin(180*u)}, {cos(180*u)} );
\addplot3[mesh,z buffer=sort,samples=20,variable=\u,domain=-1:1,variable y=\v,y domain=0:2*pi,colormap name=ends,line width=0.1pt]({sqrt(1-u^2) * cos(deg(v))},{sqrt( 1-u^2 ) * sin(deg(v))},u);
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[view={120}{30},
             xmin=-1, xmax=1, ymin=-1, ymax=1,
             xlabel=$x$, ylabel=$y$, zlabel=$z$,
             unit vector ratio = 1 1 1
            ]
  \addplot3[blue,line width=1pt,variable=\u,domain=0:1,samples=45]( {cos(360*1*u)*sin(180*u))}, {sin(360*1*u)*sin(180*u)}, {cos(180*u)} );
  \addplot3[red,line width=1pt,variable=\u,domain=0:1,samples=45]( {cos(360*2*u)*sin(180*u))}, {sin(360*2*u)*sin(180*u)}, {cos(180*u)} );
  \addplot3[green,line width=1pt,variable=\u,domain=0:1,samples=45]( {cos(360*0.5*u)*sin(180*u))}, {sin(360*0.5*u)*sin(180*u)}, {cos(180*u)} );
\addplot3[mesh,z buffer=sort,samples=20,variable=\u,domain=-1:1,variable y=\v,y domain=0:2*pi,colormap name=ends,line width=0.1pt]({sqrt(1-u^2) * cos(deg(v))},{sqrt( 1-u^2 ) * sin(deg(v))},u);
\end{axis}
\end{tikzpicture}

This one is from overhead:

\begin{tikzpicture}
\begin{axis}[view={0}{90},
%             xmin=-1, xmax=1, ymin=-1, ymax=1,
             xlabel=$x$, ylabel=$y$, zlabel=$z$,
             unit vector ratio = 1 1 1]
  \addplot3[blue,variable=\u,domain=0:1,samples=45]( {cos(360*1*u)*sin(180*u))}, {sin(360*1*u)*sin(180*u)}, {cos(180*u)} );
  \addplot3[red,variable=\u,domain=0:1,samples=45]( {cos(360*2*u)*sin(180*u))}, {sin(360*2*u)*sin(180*u)}, {cos(180*u)} );
  \addplot3[green,variable=\u,domain=0:1,samples=45]( {cos(360*0.5*u)*sin(180*u))}, {sin(360*0.5*u)*sin(180*u)}, {cos(180*u)} );
\end{axis}
\end{tikzpicture}

\end{document}

球体路径输出 (图像为空间合成。)

第一个图的较大版本: 大球体图

另一种可能性能更好、输出更漂亮的方法是从 Maple 或 GNU Octave 导入图形,您甚至可以使用它来生成 png、tikz代码或 SVG(您可以使用它来压缩gzip --best -c curves.svg > curves.svgz):

clf
colormap(gray);
[x,y,z] = sphere(20);
mesh(x,y,z);
hold on
t = [0:0.01:1];
plot3 (cos (2*pi*1*t) .* sin (pi*t), sin(2*pi*1*t) .* sin (pi*t), cos(pi*t), cos (2*pi*0.5*t) .* sin (pi*t), sin(2*pi*0.5*t) .* sin (pi*t), cos(pi*t), cos (2*pi*2*t) .* sin (pi*t), sin(2*pi*2*t) .* sin (pi*t), cos(pi*t) );

GNU Octave 图

相关内容