如何用不同的颜色来标记两个椭圆的交点。例如,椭圆本身应为黄色,而其交点应为红色。下面给出了我绘制椭圆的代码
\draw (-4,0) ellipse (8 and 3);
\draw (8,0) ellipse (8 and 3);
更新:在对各个答案的评论中,我要求显示三个省略号。
答案1
正如你所看到的这些例子和如何在 LaTeX 中绘制维恩图(尤其是:补语),只要填充颜色之一是白色,就相当容易绘制这样的椭圆。
当您想要两种不同的填充颜色并使用前面示例中描述的方法时,请确保先填充椭圆,然后再绘制它们:
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def\firstellipse{(-4,0) ellipse (8 and 3)}
\def\secondellipse{(8,0) ellipse (8 and 3)}
% colour ellipses
\fill[yellow] \firstellipse \secondellipse;
% colour intersection
\begin{scope}
\clip \firstellipse;
\fill[red] \secondellipse;
\end{scope}
% outiline of ellipses
\draw \firstellipse \secondellipse;
\end{tikzpicture}
\end{document}
编辑:回应你关于三个省略号的评论请求
想法保持不变:
- 填充省略号
- 填补你的交叉点
- 画出椭圆
因此,这给你:
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def\firstellipse{(-4,0) ellipse [x radius=8, y radius=3, rotate=150]}
\def\secondellipse{(8,0) ellipse [x radius=8, y radius=3, rotate=30]}
\def\thirdellipse{(2,-10.5) ellipse [x radius=8, y radius=3, rotate=90]}
\def\boundingbox{(-12,-16) rectangle (16,3)}
% fill ellipses
\fill[yellow] \firstellipse \secondellipse \thirdellipse;
% fill intersections
% intersection of second and third
\begin{scope}
\clip \boundingbox \firstellipse;
\clip \secondellipse;
\fill[blue] \thirdellipse;
\end{scope}
% intersection of first and third
\begin{scope}
\clip \boundingbox \secondellipse;
\clip \firstellipse;
\fill[green] \thirdellipse;
\end{scope}
% intersection of first and second
\begin{scope}
\clip \boundingbox \thirdellipse;
\clip \firstellipse;
\fill[gray] \secondellipse;
\end{scope}
% intersection of first, second and third
\begin{scope}
\clip \firstellipse;
\clip \secondellipse;
\clip \thirdellipse;
\fill[red] \boundingbox;
\end{scope}
% outline of ellipses
\draw \firstellipse \secondellipse \thirdellipse;
\end{tikzpicture}
\end{document}
如果您希望所有交叉点都变成红色,请将蓝色、绿色和灰色更改为红色。
如果你想要旋转椭圆使用
\def\firstellipse{(-4,0) ellipse [x radius=8, y radius=3, rotate=45]}
答案2
另一个选项是使用\tikzfillbetween
来自库的命令pgfplot's
fillbetween
。
\documentclass[tikz,border=2mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\draw[name path=A, fill=red] (-4,0) ellipse (8 and 3);
\draw[name path=B] (8,0) ellipse (8 and 3);
\tikzfillbetween[of=A and B]{yellow};
\end{tikzpicture}
\end{document}
答案3
您可以先用红色填充一个椭圆,然后使用以下方法绘制(填充)两个椭圆even odd rule
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
\fill[red] (-4,0) ellipse (8 and 3);
\draw[fill=yellow,even odd rule,line width=1pt] (-4,0) ellipse (8 and 3)
(8,0) ellipse (8 and 3);
\end{tikzpicture}
\end{document}
答案4
以下是尝试MetaPost(包含在 LuaLaTeX 程序中),适合对其感兴趣的人。
请注意,使用 MetaPost 绘制这种交点也并不简单。如果你看下面程序中第一个椭圆的定义,
fullcircle rotated 90 xscaled 9cm yscaled 3cm shifted (3.2cm, 0);
然后注意这rotated 90
部分。它看起来很奇怪,因为它意味着对圆应用了旋转,但如果你隐藏这部分,没有什么根本行不通。解释在于buildcycle
MetaPost 宏的复杂性(与渐近线's,顺便说一下),这些都进行了详细讨论在本主题中。
更新由于第二个椭圆现在的定义方式与以前不同(即现在通过旋转第一个椭圆),因此第一个椭圆的定义部分就变得没有必要了。我相应地简化了代码。不过,在处理这类任务时,rotated 90
最好记住宏的局限性。buildcycle
\documentclass{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
color yellow; yellow = red+green;
def erase_and_fill expr pat = unfill pat; fill pat enddef;
path fig[];
fig1 = fullcircle xscaled 9cm yscaled 3cm shifted (3.2cm, 0);
fig2 = fig1 rotated 180;
beginfig(1);
for i = 1, 2: erase_and_fill fig[i] withcolor yellow; endfor
erase_and_fill buildcycle(fig1, fig2) withcolor red;
for i = 1, 2: draw fig[i]; endfor
endfig;
\end{mplibcode}
\end{document}
现在有三个省略号,如上面 Maarten DHondt 的例子:
\documentclass{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
color yellow; yellow = red+green;
def erase_and_fill expr pat = unfill pat; fill pat enddef;
path fig[];
fig1 = fullcircle xscaled 9cm yscaled 3cm shifted (4cm, 0) rotated 30;
fig2 = fig1 rotated 120;
fig3 = fig2 rotated 120;
beginfig(1);
for i = 1 upto 3: erase_and_fill fig[i] withcolor yellow; endfor
erase_and_fill buildcycle(fig1, fig2) withcolor 0.7white;
erase_and_fill buildcycle(fig2, fig3) withcolor green;
erase_and_fill buildcycle(fig1, fig3) withcolor blue;
erase_and_fill buildcycle(fig1, fig2, fig3) withcolor red;
for i = 1 upto 3: draw fig[i]; endfor
endfig;
\end{mplibcode}
\end{document}