tikzpicture:填充多条曲线之间阴影区域的最佳实践

tikzpicture:填充多条曲线之间阴影区域的最佳实践

使用下面的最小工作示例,我已经能够用 tikzpicture 制作此图像: ![在此处输入图片描述

我想像这样在圆圈和两个外椭圆之间的区域进行阴影处理:

在此处输入图片描述

使用绘制 y=x^2 和 y=x可以通过一种略显拙劣的解决方案来实现这一点,即首先填充两个椭圆之间的区域,然后填充圆与填充椭圆所创建的垂直线之间的剩余区域。这感觉不是“最佳实践”。有没有更巧妙的方法来做到这一点?

这是用于生成第一幅图像的最小工作示例

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%draw the circle
\draw (0,0) circle(1);    
\draw[fill] (0,1) circle [radius =0.05];
\draw[fill] (0,-1) circle [radius =0.05];
\draw plot[domain=pi:2*pi] ({cos(\x r)},{.2*sin(\x r)});
\draw[dashed] plot[domain=0:pi] ({cos(\x r)},{.2*sin(\x r)});

%draw the upper ellipse
\draw plot[domain=pi:2*pi] ({0.864*cos(\x r)},{.2*sin(\x r)+.5});
\draw[dashed] plot[domain=0:pi] ({0.864*cos(\x r)},{.2*sin(\x r)+.5});

%draw the lower ellipse
\draw plot[domain=pi:2*pi] ({0.864*cos(\x r)},{.2*sin(\x r)-.5});
\draw[dashed] plot[domain=0:pi] ({0.864*cos(\x r)},{.2*sin(\x r)-.5});
\end{tikzpicture}
\end{document}

答案1

正如我的评论所述,使用省略号和剪辑对我来说似乎更容易。

阴影变成球体

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}


\begin{tikzpicture}
    \draw (0,0) circle[radius=2];
    
    %fills
    \fill[blue,opacity=0.2] (0,1) ellipse[x radius=1.72,y radius=0.4];
    \begin{scope}
        \clip (0,0) circle[radius=2];
        \fill [blue,opacity=0.6] (-1.72,1) arc[start angle = -180, end angle = 0,x radius=1.72,y radius=0.4] -- (2,1) |- (1.72,-1) arc[start angle = 0, end angle = -180,x radius=1.72,y radius=0.4] -- (-2,-1) |- cycle;
    \end{scope}
    
    
    % Upper ellipse
    \draw (-1.72,1) arc[start angle = -180, end angle = 0,x radius=1.72,y radius=0.4];
    \draw[dashed] (-1.72,1) arc[start angle = 180, end angle = 0,x radius=1.72,y radius=0.4];
    
    % Middle ellipse
    \draw (-2,0) arc[start angle = -180, end angle = 0,x radius=2,y radius=0.5];
    \draw[dashed] (-2,0) arc[start angle = 180, end angle = 0,x radius=2,y radius=0.5];
    
    % Lower ellipse
    \draw (-1.72,-1) arc[start angle = -180, end angle = 0,x radius=1.72,y radius=0.4];
    \draw[dashed] (-1.72,-1) arc[start angle = 180, end angle = 0,x radius=1.72,y radius=0.4];
    
    % Dots
    \filldraw   (0,2) circle [radius =0.05]
                (0,-2) circle [radius =0.05];
\end{tikzpicture}
\end{document}

相关内容