Graphics, Figures & TablesFilling of bounded area - Tikz

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
TobiWanKenobias
Posts: 1
Joined: Tue Jun 14, 2022 8:52 pm

Filling of bounded area - Tikz

Post by TobiWanKenobias »

Hello

Can someone help me cut this brown area, so it is only inside the dashed lines? :-)

Code: Select all

Code, edit and compile here:
\documentclass{memoir}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[style=help lines] (-0.5,-0.2) grid (8,6.5);
\centering
\clip(-0.5,-0.2) rectangle (8,6.5);
\draw[black,very thick,-latex] (-0.2,0) -- (7,0) node[right] {$x_1$};
\draw[black,very thick,-latex] (0,-0.2) -- (0,6) node[left] {$x_2$};
%Line :
\draw [dashed,thin] plot [smooth, tension=1] coordinates {(0.2,5) (3.15,5.5) (6.5,5)};
\draw [dashed,thin] plot [smooth, tension=1] coordinates {(5.7,5.7) (5.5,3) (4.5,0.1)};
\draw [dashed,thin] plot [smooth, tension=1] coordinates {(-0.2,3) (2.65,1.1) (5.5,0.4)};
\draw [dashdotted,thin] plot [smooth, tension=1] coordinates {(0.5,0) (0.5,6.2)};
\draw [dashdotted,thin] plot [smooth, tension=1] coordinates {(0,1) (8,1)};
\fill[color=brown, opacity=0.3] (0.5,1) rectangle (6,6) ;
%Text :
\draw[black,ultra thin] (0.5,4) -- (2,6) node[above] {Side constraint};
\draw[black,ultra thin] (5.3,2) -- (5.8,1.5) node[right,text width=2cm] {Behaviour constraint};
\draw[black, ultra thin] (3,3.75) -- (3,3.75) node[below] {Feasible region};
\end{tikzpicture}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Filling of bounded area - Tikz

Post by Bartman »

I'm not sure what effect you're hoping for from the \centering command at this place.

My proposed solution uses Mr. Feuersänger's answer to a related question from a German-speaking forum.

Since the first and third curves don't intersect, the adopted source code leads to an error message, which also offers the solution right away.

I chose the same class as the answerer in order to limit the output to the essentials. The example should also create the same drawing with your class.

Code: Select all

Code, edit and compile here:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{arrows.meta,backgrounds}
\begin{document}
\begin{tikzpicture}[>=Latex]
\draw[style=help lines] (-0.5,-0.2) grid (8,6.5);
\path[very thick,->,at end]
(-0.2,0) edge node[right] {$x_1$} (7,0)
(0,-0.2) edge node[left] {$x_2$} (0,6)
;
%Line :
\begin{scope}[dashed,smooth,tension=1]
\draw [name path global=curve1] plot coordinates {(0.2,5) (3.15,5.5) (6.5,5)};
\draw [name path global=curve2] plot coordinates {(5.7,5.7) (5.5,3) (4.5,0.1)};
\draw [name path global=curve3] plot coordinates {(-0.2,3) (2.65,1.1) (5.5,0.4)};
\end{scope}
\draw [dashdotted]
(0.5,0) -- (0.5,6.2) coordinate (above left)
(0,1) -- (8,1) coordinate (below right)
;
\path [
name path=1and3,
intersection segments={
of=curve1 and curve3,
sequence={A*[reverse] -- B*}% changed
}
];
\begin{scope}[on background layer]
\clip (above left) rectangle (below right);% added
\fill [
brown,
opacity=0.3,
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Post Reply