使用 tikz 制作球体外壳

使用 tikz 制作球体外壳

如何使用 tikz 绘制立体投影?

我尝试使用手动 TikZ 绘制图表,但没有成功。

有什么帮助吗?

在此处输入图片描述

答案1

本文基于这个帖子并利用了代码中指示的更多帖子。我调整了代码以接近您发布的屏幕截图。

  • 立体投影实际上是使用函数等根据平面上的输入坐标计算得出的stereox。也就是说,如果你改变PxPy(或QxQy),球面上的点也会相应改变。
  • 您可以更改视角

代码和结果:

\documentclass[tikz,border=3mm]{standalone}
\usepackage{dsfont}
% based on 
% https://tex.stackexchange.com/a/38995/121799 
% https://tex.stackexchange.com/a/76216 
% https://tex.stackexchange.com/a/59168/194703 
% https://tex.stackexchange.com/q/448920/194703 
\makeatletter 
\tikzset{ 
reuse path/.code={\pgfsyssoftpath@setcurrentpath{#1}} 
} 
\tikzset{even odd clip/.code={\pgfseteorule}, 
protect/.code={ 
\clip[overlay,even odd clip,reuse path=#1] 
(current bounding box.south west) rectangle (current bounding box.north east)
; 
}} 
\makeatother 
\usetikzlibrary{3d,arrows.meta,decorations.markings,perspective}
\tikzset{->-/.style={decoration={% https://tex.stackexchange.com/a/39282/194703
  markings,
  mark=at position #1 with {\arrow{>}}},postaction={decorate}},
  ->-/.default=0.55}

\begin{document}
\begin{tikzpicture}[declare function={%
        stereox(\x,\y)=2*\x/(1+\x*\x+\y*\y);%
        stereoy(\x,\y)=2*\y/(1+\x*\x+\y*\y);%
        stereoz(\x,\y)=(-1+\x*\x+\y*\y)/(1+\x*\x+\y*\y);
        Px=1.75;Py=-1.5;Qx=-1.5;Qy=-1.25;amax=2.5;},scale=2.5,
        line join=round,line cap=round,
        dot/.style={circle,fill,inner sep=1pt},>={Stealth[length=1.2ex]}]
 \pgfmathsetmacro{\myaz}{15}
 \path[save path=\pathSphere]   (0,0) circle[radius=1];
 \begin{scope}[3d view={\myaz}{18}]
  \draw (-amax,amax) -- (-amax,-amax) coordinate (bl) -- (amax,-amax) 
  coordinate (br)-- (amax,amax)
  %node[above left]{$z=0$}
  ;
  \begin{scope}
   \tikzset{protect=\pathSphere}
   \draw (-amax,amax) -- (amax,amax) node[below left,xshift=-2em]{$\mathds{C}$};
  \end{scope}
  \begin{scope}
   \clip[reuse path=\pathSphere];
   \draw[dashed] (-amax,amax) -- (amax,amax);
  \end{scope}
  \begin{scope}[canvas is xy plane at z=0]
   \draw[dashed] (\myaz:1) arc[start angle=\myaz,end angle=\myaz+180,radius=1];
   \draw (\myaz:1) arc[start angle=\myaz,end angle=\myaz-180,radius=1];
   \path[save path=\pathPlane] (\myaz:amax) -- (\myaz+180:amax) --(bl) -- (br) -- cycle;
   \begin{scope}
    \clip[use path=\pathPlane];
    \draw[dashed,use path=\pathSphere];
   \end{scope}
   \begin{scope}
    \tikzset{protect=\pathPlane}
    \draw[use path=\pathSphere];
   \end{scope}
  \end{scope}
  \draw[->-=0.3] (Px,Py,0) node[dot,label=below:{$w$}](w){}
  -- node[auto,pos=0.3,swap]{$\pi$} ({stereox(Px,Py)},{stereoy(Px,-1)},{stereoz(Px,Py)})
   node[dot,label=below left:{$w^*$}](w*){};
  \draw[->-] (Qx,Qy,0) node[dot,label=below:{$z$}](z){}
  -- node[auto,pos=0.5]{$\pi$} ({stereox(Qx,Qy)},{stereoy(Qx,-1)},{stereoz(Qx,Qy)})
   node[dot,label=below right:{$z^*$}](z*){};
   \draw[dashed] (w*) -- (0,0,1) node[dot,label=above:{$\zeta$}](zeta){}
   -- (z*) -- (w*);
 \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者彩色版本:

\documentclass[tikz,border=3mm]{standalone}
% based on 
% https://tex.stackexchange.com/a/38995/121799 
% https://tex.stackexchange.com/a/76216 
% https://tex.stackexchange.com/a/59168/194703 
% https://tex.stackexchange.com/q/448920/194703 
\makeatletter 
\tikzset{ 
reuse path/.code={\pgfsyssoftpath@setcurrentpath{#1}} 
} 
\tikzset{even odd clip/.code={\pgfseteorule}, 
protect/.code={ 
\clip[overlay,even odd clip,reuse path=#1] 
(current bounding box.south west) rectangle (current bounding box.north east)
; 
}} 
\makeatother 
\usetikzlibrary{3d,arrows.meta,decorations.markings,perspective}
\tikzset{->-/.style={decoration={% https://tex.stackexchange.com/a/39282/194703
  markings,
  mark=at position #1 with {\arrow{>}}},postaction={decorate}},
  ->-/.default=0.55}

\begin{document}
\pgfmathsetmacro{\myaz}{15}
\begin{tikzpicture}[declare function={%
        stereox(\x,\y)=2*\x/(1+\x*\x+\y*\y);%
        stereoy(\x,\y)=2*\y/(1+\x*\x+\y*\y);%
        stereoz(\x,\y)=(-1+\x*\x+\y*\y)/(1+\x*\x+\y*\y);
        Px=1.75;Py=-1.5;Qx=-1.5;Qy=-1.25;amax=2.5;},scale=2.5,
        line join=round,line cap=round,
        dot/.style={circle,fill,inner sep=1pt},>={Stealth[length=1.2ex]}]
 \pgfdeclarelayer{background} 
 \pgfdeclarelayer{foreground} 
 \pgfsetlayers{background,main,foreground}
 \path[save path=\pathSphere,ball color=gray,fill opacity=0.6] 
    (0,0) circle[radius=1];
 \begin{scope}[3d view={\myaz}{15}]
  \draw (-amax,amax) -- (-amax,-amax) coordinate (bl) -- (amax,-amax) 
  coordinate (br)-- (amax,amax)
  %node[above left]{$z=0$}
  ;
  \begin{scope}
   \tikzset{protect=\pathSphere}
   \draw (-amax,amax) -- (amax,amax);
  \end{scope}
  \begin{scope}
   \clip[reuse path=\pathSphere];
   \draw[dashed] (-amax,amax) -- (amax,amax);
  \end{scope}
  \begin{scope}[canvas is xy plane at z=0]
   \draw[dashed] (\myaz:1) arc[start angle=\myaz,end angle=\myaz+180,radius=1];
   \draw (\myaz:1) arc[start angle=\myaz,end angle=\myaz-180,radius=1];
   \path[save path=\pathPlane] (\myaz:amax) -- (\myaz+180:amax) --(bl) -- (br) -- cycle;
   \begin{scope}
   %\begin{pgfonlayer}{background}   
    \clip[use path=\pathPlane];
    \draw[dashed,use path=\pathSphere];
   %\end{pgfonlayer}
   \end{scope}
   \begin{scope}
    \tikzset{protect=\pathPlane}
    \draw[use path=\pathSphere];
   \end{scope}
   \begin{pgfonlayer}{background}
    \fill[blue!30,fill opacity=0.6]
     (\myaz:1) arc[start angle=\myaz,end angle=\myaz-180,radius=1]
     -- (-amax,0) -- (-amax,amax) -- (amax,amax) -- (amax,0) -- cycle;
   \end{pgfonlayer}
   \fill[blue!30,fill opacity=0.6]
     (\myaz:1) arc[start angle=\myaz,end angle=\myaz-180,radius=1]
     -- (-amax,0) -- (-amax,-amax) -- (amax,-amax) -- (amax,0) -- cycle;
  \end{scope}
  \draw[->-=0.3] (Px,Py,0) node[dot,label=below:{$w$}](w){}
  -- node[auto,pos=0.3,swap]{$\pi$} ({stereox(Px,Py)},{stereoy(Px,-1)},{stereoz(Px,Py)})
   node[dot,label=below left:{$w^*$}](w*){};
  \draw[->-] (Qx,Qy,0) node[dot,label=below:{$z$}](z){}
  -- node[auto,pos=0.5]{$\pi$} ({stereox(Qx,Qy)},{stereoy(Qx,-1)},{stereoz(Qx,Qy)})
   node[dot,label=below right:{$z^*$}](z*){};
  \begin{pgfonlayer}{background} 
   \draw[dashed] (w*) -- (0,0,1) node[dot,label=above:{$\zeta$}](zeta){}
   -- (z*) -- (w*);
  \end{pgfonlayer} 
 \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容