Как раскрасить пересечение двух эллипсов в разные цвета. Например, сами эллипсы должны быть окрашены в желтый цвет, а их пересечение в красный. Мой код для рисования эллипсов приведен ниже
\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
Вот попытка сМетаПост(входит в программу 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}
Теперь с тремя многоточиями, как в примере Мартена Д'Хондта выше:
\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}