TeX - LaTeX Asked by Archimondain on July 6, 2021
I have the folling tikz code, where several paths intersect each other. I struggle to find a way to fill the six different regions of the resulting picture, each with a different pattern (not necessarily a plain color).
documentclass{article}
usepackage{tikz} %used for theorem style
usetikzlibrary{positioning}
usetikzlibrary{hobby}
usetikzlibrary{intersections}
begin{document}
begin{tikzpicture}
coordinate (upleft) at (0,0);
coordinate[right = 12cm of upleft] (upright);
coordinate[below = 14cm of upright] (downright);
coordinate[below = 14cm of upleft] (downleft);
draw[name path=UP] (upleft) -- (upright);
draw[name path=RIGHT] (upright) -- (downright);
draw[name path=DOWN] (downright) -- (downleft);
draw[name path=LEFT] (downleft) -- (upleft);
coordinate[above right = 8cm and 6cm of downleft] (halt);
coordinate[right = 2.5cm of upleft] (coneupleft);
coordinate[left = 2.5cm of upright] (coneupright);
coordinate[right = 4cm of downleft] (conedownleft);
coordinate[left = 4cm of downright] (conedownright);
%left to right Curve
coordinate[below = 2cm of upleft] (curve1left);
coordinate[below = 2cm of upright] (curve1right);
coordinate[below = 4cm of halt] (curve1middle);
coordinate[left = 3cm of halt] (curve1middle1);
coordinate[right = 3cm of halt] (curve1middle2);
draw[name path=HIGH] (curve1left) to [curve through = {(curve1middle1) (curve1middle) (curve1middle2)}] (curve1right);
%up to bottom curves
coordinate[right = 1cm of upleft] (vcurve1upl);
coordinate[left = 1cm of upright] (vcurve1upr);
coordinate[left = 3cm of conedownleft] (vcurve1bottoml);
coordinate[right = 3cm of conedownright] (vcurve1bottomr);
coordinate[left = 3.5cm of halt] (vcurve1ml);
coordinate[right = 3.5cm of halt] (vcurve1mr);
draw[name path=DNCLEFT] (vcurve1upl) to [curve through = {(vcurve1ml)}] (vcurve1bottoml);
draw[name path=DNCRIGHT] (vcurve1upr) to [curve through = {(vcurve1mr)}] (vcurve1bottomr);
end{tikzpicture}
end{document}
The result looks like this:
The goal is to fill the six regions with different patterns, if possible without touching the existing code, but only by adding new lines of code.
From what I could see looking at various similar questions, there may be a possibility with a combination of pieces of code like:
fill[orange, intersection segments={
of=HIGH and DNCLEFT,
sequence={L2--R2}
}];
However the above code is made to fill a pattern between two paths and not more. Also I do not understand the meaning of L2
and R2
(which apparently could also range from R0
to R2
or L0
to L2
, and used with some reverse
keyword), so I have trouble mixing them together to achieve what I want.
Note that the full picture I’m working with has much more regions than the one I’m giving here, which is sort of a minimal exemple.
Ideally a combination of some clipping command of the form "clip everything to the left/right/top/bottom of a given path*" would be great, but I could not find how to do it.
You can combine the intersection segments to a new path that you can use for another fillbetween
with yet another path, and so on. But here maybe simple clips are easier to deal with. You can use the insert path
key to avoid unnecessary repetition. intersections
is not needed here, but I kept all the name path
keys in.
documentclass{article}
usepackage{tikz} %used for theorem style
usetikzlibrary{positioning}
usetikzlibrary{hobby}
usetikzlibrary{intersections}
usetikzlibrary{backgrounds}
begin{document}
begin{tikzpicture}
coordinate (upleft) at (0,0);
coordinate[right = 12cm of upleft] (upright);
coordinate[below = 14cm of upright] (downright);
coordinate[below = 14cm of upleft] (downleft);
draw[name path=UP] (upleft) -- (upright);
draw[name path=RIGHT] (upright) -- (downright);
draw[name path=DOWN] (downright) -- (downleft);
draw[name path=LEFT] (downleft) -- (upleft);
coordinate[above right = 8cm and 6cm of downleft] (halt);
coordinate[right = 2.5cm of upleft] (coneupleft);
coordinate[left = 2.5cm of upright] (coneupright);
coordinate[right = 4cm of downleft] (conedownleft);
coordinate[left = 4cm of downright] (conedownright);
%left to right Curve
coordinate[below = 2cm of upleft] (curve1left);
coordinate[below = 2cm of upright] (curve1right);
coordinate[below = 4cm of halt] (curve1middle);
coordinate[left = 3cm of halt] (curve1middle1);
coordinate[right = 3cm of halt] (curve1middle2);
tikzset{HIGH/.style={insert path={(curve1left) to [curve through = {(curve1middle1) (curve1middle) (curve1middle2)}] (curve1right)}}}
draw[name path=HIGH,HIGH] ;
%up to bottom curves
coordinate[right = 1cm of upleft] (vcurve1upl);
coordinate[left = 1cm of upright] (vcurve1upr);
coordinate[left = 3cm of conedownleft] (vcurve1bottoml);
coordinate[right = 3cm of conedownright] (vcurve1bottomr);
coordinate[left = 3.5cm of halt] (vcurve1ml);
coordinate[right = 3.5cm of halt] (vcurve1mr);
tikzset{DNCLEFT/.style={insert path={(vcurve1upl) to [curve through = {(vcurve1ml)}] (vcurve1bottoml)}},
DNCRIGHT/.style={insert path={(vcurve1upr) to [curve through = {(vcurve1mr)}] (vcurve1bottomr)}}}
draw[name path=DNCLEFT,DNCLEFT] ;
draw[name path=DNCRIGHT,DNCRIGHT];
begin{scope}[on background layer]
begin{scope}
fill[orange,HIGH] -- (upright) -- (upleft) -| cycle;
end{scope}
%
begin{scope}
fill[cyan,HIGH] -- (downright) -- (downleft) -| cycle;
end{scope}
%
begin{scope}
clip[DNCLEFT] -- (downleft) |- (upleft) -| cycle;
fill[red,HIGH] -- (upright) -- (upleft) -- cycle;
end{scope}
%
begin{scope}
clip[DNCRIGHT] -- (downright) -- (upright) -| cycle;
fill[blue,HIGH] -- (upright) -| cycle;
end{scope}
%
begin{scope}
clip[DNCLEFT] -- (downleft) |- (upleft) -| cycle;
fill[magenta,HIGH] -- (downright) -- (downleft) -| cycle;
end{scope}
%
begin{scope}
clip[DNCRIGHT] -- (downright) -- (upright) -| cycle;
fill[purple,HIGH] -- (downright) -- (downleft) -| cycle;
end{scope}
end{scope}
end{tikzpicture}
end{document}
Correct answer by user231225 on July 6, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP