我想填充由两个椭圆和两条线包围的部分。该部分在图中标为“此处”。我试过multiclip
没有成功。有没有更简单的方法?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes, calc, fit, arrows.meta, arrows, patterns,
positioning, intersections, 3d, matrix}
\usetikzlibrary{decorations.pathmorphing, decorations.shapes}
\begin{document}
\begin{tikzpicture}
\draw (0,0) ellipse (2 and 1);
\draw (0,0) ellipse (3 and 2);
\draw (0,0) ellipse (4 and 3);
\draw (0,1) -- (0,3);
\draw (0,-1) -- (0,-3);
\draw (2,0) -- (4,0);
\draw (-2,0) -- (-4,0);
\draw (1.36,0.75) -- (3.0,2);
\draw (-1.36,0.75) -- (-3.0,2);
\draw (1.36,-0.75) -- (3.0,-2);
\draw (-1.36,-0.75) -- (-3.0,-2);
\node at (1,1.4){Here};
\end{tikzpicture}
\end{document}
答案1
这里有两个解决方案。第一个解决方案是,我将多边形剪辑与椭圆填充相结合。第二个解决方案是,我计算了给定点对应的弧角(实际上是它们与中间椭圆的交点)。
\documentclass[multi=tikzpicture]{standalone}% or just [tikz]
\usepackage{tikz}
\usetikzlibrary{shapes, calc, fit, arrows.meta, arrows, patterns,
positioning, intersections, 3d, matrix}
\usetikzlibrary{decorations.pathmorphing, decorations.shapes}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (0,1) -- (0,3) -- (3,2) -- (1.36,0.75) -- cycle;
\fill[pink, even odd rule] (0,0) ellipse (3 and 2) ellipse (2 and 1);
\end{scope}
\draw (0,0) ellipse (2 and 1);
\draw (0,0) ellipse (3 and 2);
\draw (0,0) ellipse (4 and 3);
\draw (0,1) -- (0,3);
\draw (0,-1) -- (0,-3);
\draw (2,0) -- (4,0);
\draw (-2,0) -- (-4,0);
\draw (1.36,0.75) -- (3.0,2);
\draw (-1.36,0.75) -- (-3.0,2);
\draw (1.36,-0.75) -- (3.0,-2);
\draw (-1.36,-0.75) -- (-3.0,-2);
\node at (1,1.4){Here};
\end{tikzpicture}
\begin{tikzpicture}
\pgfmathsetmacro{\inner}{atan2(0.75,1.36/2)}%
\path[name path=A] (0,0) ellipse (3 and 2);
\path[name path=B] (1.36,0.75) -- (3.0,2);
\path[name intersections={of=A and B, by=C}] (C);
\pgfgetlastxy{\Cx}{\Cy}
\pgfmathsetmacro{\outer}{atan2(\Cy/2,\Cx/3)}%
\fill[pink] (0,1) -- (0,2) arc[x radius=3, y radius=2, start angle=90, end angle={\outer}]
-- (1.36,0.75) arc[x radius=2, y radius=1, start angle={\inner}, end angle=90] -- cycle;
\draw (0,0) ellipse (2 and 1);
\draw (0,0) ellipse (3 and 2);
\draw (0,0) ellipse (4 and 3);
\draw (0,1) -- (0,3);
\draw (0,-1) -- (0,-3);
\draw (2,0) -- (4,0);
\draw (-2,0) -- (-4,0);
\draw (1.36,0.75) -- (3.0,2);
\draw (-1.36,0.75) -- (-3.0,2);
\draw (1.36,-0.75) -- (3.0,-2);
\draw (-1.36,-0.75) -- (-3.0,-2);
\node at (1,1.4){Here};
\end{tikzpicture}
\end{document}
答案2
这是 John Kormylo 的答案的替代方案。在这种情况下,这不是必需的,但总的来说clip even odd rule
非常有用。
\documentclass{standalone}
\usepackage{tikz}
% see https://tex.stackexchange.com/a/359661/121799
\tikzset{clip even odd rule/.code={\pgfseteorule}}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip[clip even odd rule] (0,0) ellipse (2 and 1) (0,0) ellipse (3 and 2);
\fill[blue!20] (0,0) -- (0,3) -- (3,2) -- (1.36,0.75);
\end{scope}
\draw (0,0) ellipse (2 and 1);
\draw (0,0) ellipse (3 and 2);
\draw (0,0) ellipse (4 and 3);
\draw (0,1) -- (0,3);
\draw (0,-1) -- (0,-3);
\draw (2,0) -- (4,0);
\draw (-2,0) -- (-4,0);
\draw (1.36,0.75) -- (3.0,2);
\draw (-1.36,0.75) -- (-3.0,2);
\draw (1.36,-0.75) -- (3.0,-2);
\draw (-1.36,-0.75) -- (-3.0,-2);
\node at (1,1.4){Here};
\end{tikzpicture}
\end{document}
答案3
这是一个基本上基于两个内椭圆的参数表示的解决方案(虽然我使用ellipse
节点形状来shapes.geometric
绘制完整的椭圆,这是最简单的部分):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
% Define the start and end angles of the sector to be filled
\def\sectorStartAngle{45}
\def\sectorEndAngle{90}
% Allows scaling the ellipses
\def\myUnit{8em}
% Dimensions of the inner ellipse
\def\innerXDiameter{2} % in \myUnit
\def\innerYDiameter{1} % in \myUnit
% Dimensions of the middle ellipse
\def\middleXDiameter{3} % in \myUnit
\def\middleYDiameter{2} % in \myUnit
% Dimensions of the outer ellipse
\def\outerXDiameter{4} % in \myUnit
\def\outerYDiameter{3} % in \myUnit
\begin{document}
\begin{tikzpicture}[
my ellipse/.style args={#1and #2}{%
draw, color=blue, shape=ellipse, inner sep=0pt,
minimum width={(#1)*\myUnit},minimum height={(#2)*\myUnit}}]
\node[my ellipse={\innerXDiameter and \innerYDiameter}] (inner) at (0,0) {};
\node[my ellipse={\middleXDiameter and \middleYDiameter}] (middle) at (0,0) {};
\node[my ellipse={\outerXDiameter and \outerYDiameter}] (outer) at (0,0) {};
% Parameter transformations for the two inner ellipses. These transformations
% allow one to specify the plot parameter in degrees as if we had a circle
% parametrization. Thanks to this, the start and end angles can be given in
% degrees below, instead of in some skewed approximation.
\def\innerParam{atan2(\innerXDiameter*sin(\theta), \innerYDiameter*cos(\theta))}
\def\middleParam{atan2(\middleXDiameter*sin(\theta), \middleYDiameter*cos(\theta))}
\fill[red!20, smooth, variable=\theta]
plot[domain=\sectorStartAngle:\sectorEndAngle]
({0.5*\innerXDiameter*\myUnit*cos(\innerParam)},
{0.5*\innerYDiameter*\myUnit*sin(\innerParam)})
--
plot[domain=\sectorEndAngle:\sectorStartAngle]
({0.5*\middleXDiameter*\myUnit*cos(\middleParam)},
{0.5*\middleYDiameter*\myUnit*sin(\middleParam)})
-- cycle;
\foreach \i in {0, ..., 7} {
\draw[help lines] (node cs:name=inner, angle=45*\i) --
(node cs:name=outer, angle=45*\i);
}
\end{tikzpicture}
\end{document}
注意:有一种方法可以稍微简化使用该arc
操作要填充的路径的定义,但是如下:
(node cs:name=inner, angle=\sectorStartAngle)
arc[start angle=\sectorStartAngle, end angle=\sectorEndAngle,
x radius=0.5*\innerXDiameter*\myUnit,
y radius=0.5*\innerYDiameter*\myUnit]
做不是从上面我填充的路径中给出第一个弧。无论如何,使用上面所做的参数图对其他问题非常有帮助(它“赋予了权力”)。