如何为两三条圆弧之间的区域着色?

如何为两三条圆弧之间的区域着色?

这是我第一次尝试使用 Tikz,我正在尝试找出一种方法来为 P_{\bot} 和 Q_{\bot} 之间的区域着色。我尝试标记交叉点,以便我可以单独为该区域着色,但(见图)这不是我想要的。

有人有想法吗?这是我到目前为止的代码:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning,intersections,quotes,angles}

\begin{document}
    \begin{tikzpicture}
    \def\r{2cm} % sphere radius
\shade[ball color = gray!40, opacity = 0.2] (0,0) circle (\r);
    \draw (0,0) circle (\r);
    \draw[blue, thick,name path=p] (-2,0) arc (180:360:2 and 0.6);
    \draw[blue,thick,dashed,name path=p'] (2,0) arc (0:180:2 and 0.6);  
    \draw[dashed,blue] (0,2) coordinate (P) -- (0,0) coordinate (O) -- (2,0) 
coordinate (P')
pic["$\cdot$",draw,solid] {angle=P'--O--P};
\fill[black] (O) circle (1pt);
\node (P') [pin={[pin edge={blue},blue]0:$P_{\bot}$}] at (P') {};
\draw[red, very thick] (P) arc (90:130:2) coordinate (Q) node [pos=0.5, above, red, ] {$\gamma$};
\fill[blue] (P) circle (2pt) node [above, blue] {$P$};
\draw[dashed,blue] (Q) -- (O);
\draw (Q) arc (130:220:2) coordinate (Q') ;
\fill [blue] (Q) circle (2pt) node [above left, blue] {Q};
\draw[dashed,blue] (Q') -- (O) ;
\node (Q') [pin={[pin edge={blue},blue]180:$Q_{\bot}$}] at (Q') {};
\pic["$\cdot$",draw,solid, blue] {angle=Q--O--Q'};
\draw[rotate around={40:(0,0)},blue,thick,name path=q] (-2,0) arc (180:360:2 
and 0.6) coordinate (Q'');
\draw[rotate around={40:(0,0)},blue,thick,dashed,name path=q'] (2,0) arc 
(0:180:2 and 0.6);
\draw[name path=a] (-2,0) arc (180:220:2);
\path[name intersections={of=a and p, by={ap}}];
\path[name intersections={of=a and q, by={aq}}];
\path[name intersections={of=p and q, by={pq}}] ;
\path[name intersections={of=p' and q', by={p'q'}}]; 
\fill[red, opacity=0.5] (ap) -- (pq) -- (aq)--cycle;
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

fillbetween 库可以在这里提供帮助。

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.15}

\usetikzlibrary{shapes,positioning,intersections,quotes,angles}

\begin{document}
    \begin{tikzpicture}
    \def\r{2cm} % sphere radius
\shade[ball color = gray!40, opacity = 0.2] (0,0) circle (\r);
    \draw (0,0) circle (\r);
    \draw[blue, thick,name path=p] (-2,0) arc (180:360:2 and 0.6);
    \draw[blue,thick,dashed,name path=p'] (2,0) arc (0:180:2 and 0.6);  
    \draw[dashed,blue] (0,2) coordinate (P) -- (0,0) coordinate (O) -- (2,0) 
coordinate (P')
pic["$\cdot$",draw,solid] {angle=P'--O--P};
\fill[black] (O) circle (1pt);
\node (P') [pin={[pin edge={blue},blue]0:$P_{\bot}$}] at (P') {};
\draw[red, very thick] (P) arc (90:130:2) coordinate (Q) node [pos=0.5, above, red, ] {$\gamma$};
\fill[blue] (P) circle (2pt) node [above, blue] {$P$};
\draw[dashed,blue] (Q) -- (O);
\draw (Q) arc (130:220:2) coordinate (Q') ;
\fill [blue] (Q) circle (2pt) node [above left, blue] {Q};
\draw[dashed,blue] (Q') -- (O) ;
\node (Q') [pin={[pin edge={blue},blue]180:$Q_{\bot}$}] at (Q') {};
\pic["$\cdot$",draw,solid, blue] {angle=Q--O--Q'};
\draw[rotate around={40:(0,0)},blue,thick,name path=q] (-2,0) arc (180:360:2 
and 0.6) coordinate (Q'');
\draw[rotate around={40:(0,0)},blue,thick,dashed,name path=q'] (2,0) arc 
(0:180:2 and 0.6);
\draw[name path=a] (-2,0) arc (180:220:2);
\fill [intersection segments={
            of=p and q,
            sequence={L1 -- R1[reverse]}},
        red, opacity=0.5
];
\fill [intersection segments={
            of=a and q,
            sequence={L1 -- R1}},
        red, opacity=0.5
];
\path[name intersections={of=a and p, by={ap}}];
\path[name intersections={of=a and q, by={aq}}];
\path[name intersections={of=p and q, by={pq}}] ;
\path[name intersections={of=p' and q', by={p'q'}}]; 
\end{tikzpicture}
\end{document}

在此处输入图片描述

解释:当对相交路径进行填充时,路径会分解为段。第一条路径可以称为LA,第二条路径称为RB。在您的例子中,只有一个交点,因此第一个语句中的 L1 和 和 R1 是交点左侧上大圆和下大圆的部分,当然,必须反向运行下路径。请注意,可以将所有内容合并到一个填充命令中:

\fill [intersection segments={
            of=p and q,
            sequence={L1 -- R1[reverse]}},
        red, opacity=0.5
] (220:2) arc (220:180:2);

这是一个个人品味的问题,选择哪一种会更舒服。

相关内容