如何在球体中绘制月牙并使用 TiKz 进行着色

如何在球体中绘制月牙并使用 TiKz 进行着色

为了简化这个问题,我想绘制以下图表:

卢内

此图表复制自双曲几何-三角形和高斯帽 我的问题是如何绘制阴影。球体上的圆圈很容易绘制,但阴影似乎更难。

显然,角是两个半平面的交点,而月牙是两个半球的交点。因此,通过对半球进行适当的阴影处理和叠加,我们可能能够得到这样的图形。如果是这样的话,现在的问题是如何对半球进行阴影处理?那么这将我引向这个画一个半球 帖子,顺便说一句尚未答复,但我相信这是一个好的开始。

谢谢。

答案1

这是假 3D 的尝试元帖子这可能会鼓励某人在 TikZ 中展示类似的东西。TikZ 没有,但我相信buildcycle你可以用这个库获得相同的效果。intersections

在此处输入图片描述

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);

r = 3cm;

color g[]; % some Shades of Grey...
g1 = .8 white;
g2 = .7 white;
g3 = .6 white;
g4 = .5 white;
g5 = .4 white;
g6 = .3 white;

path c[];
c1 = fullcircle scaled 2r;
c2 = c1 yscaled 1/2 rotated -10;
c3 = c1 yscaled 1/2 rotated +96;
c4 = c1 yscaled 1/4 rotated +42;

fill c1 withcolor g1;

fill buildcycle( subpath (0,4) of c3, subpath (4,0) of c4, subpath (4,8) of c3 ) withcolor g2;
fill buildcycle( subpath (2,6) of c4, subpath (4,0) of c3                      ) withcolor g2;
fill buildcycle( subpath (4,8) of c4, subpath (0,4) of c1, c3                  ) withcolor g4;
fill buildcycle( subpath (6,3) of c4, subpath (3,7) of c1, subpath (2,5) of c3 ) withcolor g5;

draw subpath (0,4) of c2 withcolor g3; 
draw subpath (0,4) of c3 withcolor g3; 
draw subpath (0,4) of c4 withcolor g3; 

draw subpath (0,2) of c2 cutbefore subpath (4,8) of c4 cutafter c3 withcolor g6; 
draw subpath (0,2) of c4 cutafter c3                   withcolor g6; 
draw subpath (2,4) of c3 cutbefore subpath (4,8) of c4 withcolor g6; 

draw subpath (4,8) of c2;
draw subpath (4,8) of c3;
draw subpath (4,8) of c4;

label(btex $\alpha$ etex, (subpath (4,8) of c3 intersectionpoint subpath (4,8) of c4) shifted (-4,-12) );
label(btex $\beta$  etex, (subpath (4,8) of c4 intersectionpoint subpath (4,8) of c2) shifted (+16,+4) );
label(btex $\gamma$ etex, (subpath (4,8) of c2 intersectionpoint subpath (4,8) of c3) shifted (-4,+6) );

draw c1 withcolor g6;
undraw c1 scaled 1.4;

endfig;
end.

答案2

这是 3D 的 tikz 解决方案,带有阴影和更逼真的月牙形状。我希望可以通过一些命令定义缩短代码,欢迎提出建议。

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{fadings}

\begin{document}
\begin{center}
  \begin{tikzpicture}[scale=3]
    \begin{scope}[rotate=-10]
      \draw [very thin, opacity=0.5] (1,0) arc [x radius=1, y radius=0.5, start angle=0, end angle=180];
      \draw [very thin] (1,0) arc [x radius=1, y radius=0.5, start angle=0, end angle=-180];
    \end{scope}
    \begin{scope}[rotate=42]
      \draw [very thin, opacity=0.5] (1,0) arc [x radius=1, y radius=0.25, start angle=0, end angle=180];
      \draw [very thin] (1,0) arc [x radius=1, y radius=0.25, start angle=0, end angle=-180];
    \end{scope}
    \begin{scope}[rotate=96]
      \draw [very thin, opacity=0.5] (1,0) arc [x radius=1, y radius=0.5, start angle=0, end angle=180];
      \draw [very thin] (1,0) arc [x radius=1, y radius=0.5, start angle=0, end angle=-180];
    \end{scope}
    \begin{scope}
      \clip [rotate=42] (1,0) arc [x radius=1, y radius=0.25, start angle=0, end angle=-180] -- (-1,-1) -- (1,-1) -- (1,0);
      \clip [rotate=96] (1,0) arc [x radius=1, y radius=0.5, start angle=0, end angle=-180] -- (-1,1) -- (1,1) -- (1,0);
      \shade [ball color = red, opacity = 0.7] (0,0) circle [radius=1];
    \end{scope}
    \begin{scope}
      \clip [rotate=42] (1,0) arc [x radius=1, y radius=0.25, start angle=0, end angle=-180] -- (-1,1) -- (1,1) -- (1,0);
      \clip [rotate=96] (1,0) arc [x radius=1, y radius=0.5, start angle=0, end angle=-180] -- (-1,-1) -- (1,-1) -- (1,0);
      \shade [ball color = red, opacity = 0.7] (0,0) circle [radius=1];
    \end{scope}
    \begin{scope}[transform canvas={rotate=180}, rotate=180]
      \clip [rotate=42] (1,0) arc [x radius=1, y radius=0.25, start angle=0, end angle=360];
      \clip [rotate=96] (1,0) arc [x radius=1, y radius=0.5, start angle=0, end angle=180] -- (-1,1) -- (1,1) -- (1,0);
      \shade [ball color = red!50!black, opacity = 0.35] (0,0) circle [radius=1];
    \end{scope}
    \begin{scope}[transform canvas={rotate=180}, rotate=180]
      \clip [rotate=42] (1,0) arc [x radius=1, y radius=0.25, start angle=0, end angle=180] -- (-1,1) -- (1,1) -- (1,0);
      \clip [rotate=96] (1,0) arc [x radius=1, y radius=0.5, start angle=0, end angle=360];
      \shade [ball color = red!50!black, opacity = 0.35] (0,0) circle [radius=1];
    \end{scope}
    \begin{scope}
      \clip [rotate=96] (1,0) arc [x radius=1, y radius=0.5, start angle=0, end angle=-180] -- (-1,1) -- (1,1) -- (1,0);
      \clip [rotate=42] (1,0) arc [x radius=1, y radius=0.25, start angle=0, end angle=-180] -- (-1,1) -- (1,1) -- (1,0);
      \shade [ball color = red!60, opacity = 0.4] (0,0) circle [radius=1];
    \end{scope}
    \begin{scope}
      \clip [rotate=96] (1,0) arc [x radius=1, y radius=0.5, start angle=0, end angle=-180] -- (-1,-1) -- (1,-1) -- (1,0);
      \clip [rotate=42] (1,0) arc [x radius=1, y radius=0.25, start angle=0, end angle=-180] -- (-1,-1) -- (1,-1) -- (1,0);
      \shade [ball color = red!60, opacity = 0.4] (0,0) circle [radius=1];
    \end{scope}
  \end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

答案3

这个答案的功劳应该归功于@Thruston,他告诉我,我们必须从二维角度思考才能绘制三维。我的问题是,我在思考球体,这太复杂了。我还使用了他的 Metacode 帖子作为我在此处附加的 tikz 代码的指南。

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{calc,3d,shapes, pgfplots.external, intersections}


\begin{document}

\begin{tikzpicture}[]
  \coordinate (O) at (0,0);

  \def\R{3cm}

  %outside sphere
  \def\c1{(O) circle (\R)}
  \fill[ball color=white!10, opacity=0.3, name path=c1] \c1;


  %one lune side
  \draw[rotate=96, name path=c2, yscale=0.5, color=gray, opacity=0.0] \c1;
  %the other lune side
  \draw[rotate=42, name path=c3, yscale=0.5, color=gray, opacity=0.0] \c1;

  % find intersections of each lune side with outside circle
  \path [name intersections={of=c1 and c2, 
           by={c121, c122}}];

  % these two ellipses intersect at 4 points
  \path [name intersections={of=c1 and c3, 
           by={c131, c132,c133,c134}}];

  % find intersections between c2 and c3
  \path [name intersections={of=c2 and c3, 
           by={c231, c232, c233, c234}}];


  % Locate points (a preview) uncomment the following lines
  % to better understand the figure
   %\node[] at (c121) {c121};
  % \node[] at (c122) {c122};
  % \node[] at (c131) {c131};
  % \node[] at (c134) {c134};
  % \node[] at (c231) {c231};
  % \node[] at (c232) {c232};
  % \node[] at (c233) {c233};
  % \node[] at (c234) {c234};


  \path[name path=c4, rotate=-30, yscale=0.30] \c1;

  % find intersections between c1,c2,c3, and c4
  \path [name intersections={of=c2 and c4, 
           by={c241,c242,c243,c244}}];
  \path [name intersections={of=c3 and c4, 
           by={c341,c342,c343,c344}}];
  \path [name intersections={of=c1 and c4, 
           by={c141,c142,c143,c144}}];


   % fill lunes
   % back lune
   \fill[color=black , opacity=0.2]  (c121) to [bend left=23] (c131)
   to [bend right=60] (c134) to [bend right=23] (c122) to [bend left=60]  (c121);

   % front lune
     \fill[color=black , opacity=0.4] (c121) to [bend left=23] (c131) to 
     [bend left] (c233) to [bend left] (c134) to [bend right=24] (c122)
     to [bend right]  (c233) to [bend right] (c121);



   %\node[] at (c244) {c244};
   %\node[] at (c341) {c341};
   %\node[] at (c342) {c342};
   %\node[] at (c343) {c343};
   %\node[] at (c344) {c344};
   %\node[] at (c141) {c141};
   %\node[] at (c142) {c142};
   %\node[] at (c143) {c143};
   %\node[] at (c144) {c144};

 % front circle
   \draw[opacity=0.8, name path= c4]  (c141) to [bend right=89] (c142);
 % back circle
   \draw[opacity=0.2]  (c141) to [bend left=89] (c142);


   % labels
   \node [yshift=-3mm, xshift=-1mm] at (c233) {\scriptsize $\alpha$};
   \node [yshift=-5mm, xshift=-5mm] at (c343) {\scriptsize $\beta$};
   \node [yshift=-4mm, xshift=-4mm] at (c244) {\scriptsize $\gamma$};
\end{tikzpicture}


 \end{document}

图如下。“节点”上的注释是我的“脚手架”。

在此处输入图片描述

相关内容