如何用 TikZ 绘制球体的一段?

如何用 TikZ 绘制球体的一段?

我正在尝试使用 tikz 将黑色平面替换为球体的一部分:

延拓伪弧长

球体具有中心H(Y_i)和半径,所有从(绿点)到(蓝点)||H(Y_i) , H(Y_i+1^0)||的点都位于该球体上(=> 对应于左上角轴系指定的平面中的圆弧)。k=0k

任何使用 tikz 添加球体一部分的建议都将不胜感激。谢谢。

更新球面段答案

在@marmot 的帮助下:

marmot_answer_improvement

再次感谢这个精彩的渲染。

答案1

这篇文章的目的是定义一种绘制球体一部分的样式。更具体地说,它将绘制一个纬度和经度在一定范围内的线段。绘制这个线段很简单,只需说

\draw[thin,fill=white,fill opacity=0.6,
 sphere segment={phi from 60 to 120 and theta from -10 to 50 and radius 4}];

其中 phi 和 theta 是经度和纬度参数。

\documentclass[tikz,border=3.14mm]{standalone} 
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d} 
\begin{document} 
\tdplotsetmaincoords{70}{30} 
\begin{tikzpicture}[tdplot_main_coords,bullet/.style={fill,circle,inner
sep=1pt},sphere segment/.style args={%
phi from #1 to #2 and theta from #3 to #4 and radius #5}{insert path={%
 plot[variable=\x,smooth,domain=#2:#1] 
 (xyz spherical cs:radius=#5,longitude=\x,latitude=#3)
 -- plot[variable=\x,smooth,domain=#3:#4] 
 (xyz spherical cs:radius=#5,longitude=#1,latitude=\x)
 --plot[variable=\x,smooth,domain=#1:#2] 
 (xyz spherical cs:radius=#5,longitude=\x,latitude=#4)
 -- plot[variable=\x,smooth,domain=#4:#3] 
 (xyz spherical cs:radius=#5,longitude=#2,latitude=\x)}},
>=stealth,declare function={f(\x)=exp(-2+0.5*\x);}] 
 \draw[thick] (0,0,0) -- (4,0,0);
 \draw[thick,orange] plot[variable=\x,smooth,domain=0:4] ({\x},0,{f(\x)});
 % note: this domain is an approximation, it should really be 
 % from 0 to xmax where xmax is the solution of x^2+f(x)^2=4^2
 \draw[thin,fill=white,fill opacity=0.6,
 sphere segment={phi from 60 to 120 and theta from -10 to 50 and radius 4}] ; 
 \draw[thick,->] (4,0,0) -- (6,0,0);
 \draw[thick,orange] plot[variable=\x,smooth,domain=4:6] ({\x},0,{f(\x)});
 % should be xmax:6
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者 Henri Menke 的版本,他建议使用以下语法

\clip[sphere segment={r=4, phi=60:120, theta=-10:50}];

剪辑用于剪切球体的一部分。(球体只是一个圆圈,tdplot_screen_coordinate因为任何球体的正交投影在屏幕坐标中都是一个圆圈。很可能我重新发明了一些东西……)

\documentclass[tikz,border=3.14mm]{standalone} 
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d} 
\tikzset{3d stuff/.is family,
3d stuff/.cd,
parse domain/.code args={#1:#2}{\def\xmin{#1}\def\xmax{#2}},
sphere segment/.is family,
sphere segment/.cd,
r/.initial=1, 
phi/.initial=0:30, 
theta/.initial=0:30
}
\begin{document} 
\tdplotsetmaincoords{70}{30} 
\begin{tikzpicture}[tdplot_main_coords,bullet/.style={fill,circle,inner
sep=1pt},sphere segment/.style={
/utils/exec=\tikzset{3d stuff/sphere segment/.cd,#1}%
\pgfkeys{/tikz/3d stuff/parse domain/.expanded=\pgfkeysvalueof{/tikz/3d stuff/sphere segment/phi}}
\edef\phimin{\xmin}
\edef\phimax{\xmax}
\pgfkeys{/tikz/3d stuff/parse domain/.expanded=\pgfkeysvalueof{/tikz/3d stuff/sphere segment/theta}}
\edef\thetamin{\xmin}
\edef\thetamax{\xmax},
insert path={%
plot[variable=\x,smooth,domain=\phimax:\phimin] 
 (xyz spherical cs:radius=\pgfkeysvalueof{/tikz/3d stuff/sphere segment/r},
  longitude=\x,latitude=\thetamin)
-- plot[variable=\x,smooth,domain=\thetamin:\thetamax] 
 (xyz spherical cs:radius=\pgfkeysvalueof{/tikz/3d stuff/sphere segment/r},
 longitude=\phimin,latitude=\x)
--plot[variable=\x,smooth,domain=\phimin:\phimax] 
 (xyz spherical cs:radius=\pgfkeysvalueof{/tikz/3d stuff/sphere segment/r},
 longitude=\x,latitude=\thetamax)
-- plot[variable=\x,smooth,domain=\thetamax:\thetamin] 
 (xyz spherical cs:radius=\pgfkeysvalueof{/tikz/3d stuff/sphere segment/r},
 longitude=\phimax,latitude=\x) --cycle}},
>=stealth,declare function={f(\x)=exp(-2+0.5*\x);}] 
 \draw[thick] (0,0,0) -- (4,0,0);
 \draw[thick,orange] plot[variable=\x,smooth,domain=0:4] ({\x},0,{f(\x)});
 % note: this domain is an approximation, it should really be 
 % from 0 to xmax where xmax is the solution of x^2+f(x)^2=4^2
 \begin{scope}
  \clip[sphere segment={r=4, phi=60:120, theta=-10:50}]; 
  \shade[tdplot_screen_coords,ball color=gray!30,opacity=0.5] 
   (0,0) circle[radius=4];
 \end{scope} 
 \draw[thick,->] (4,0,0) -- (6,0,0);
 \draw[thick,orange] plot[variable=\x,smooth,domain=4:6] ({\x},0,{f(\x)});
 % should be xmax:6
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容