Graphics, Figures & Tables ⇒ A question about filling a region with colour and pattern
A question about filling a region with colour and pattern
As seen in the attached pdf file (and Latex input file), I have a region defined by 2 parabola segments and a line (region highlighted in red).
I would like to fill this region using a shape/pattern construct (see Latex file), but I have problem with defining my region's boundary to achieve this.
Any help is highly appreciated!
Best regards,
Kent Holing
NORWAY
I would like to fill this region using a shape/pattern construct (see Latex file), but I have problem with defining my region's boundary to achieve this.
Any help is highly appreciated!
Best regards,
Kent Holing
NORWAY
- Attachments
-
- latexforum2.pdf
- (3.55 KiB) Downloaded 295 times
-
- latexforum2.tex
- (1.63 KiB) Downloaded 500 times
NEW: TikZ book now 40% off at Amazon.com for a short time.

- Stefan Kottwitz
- Site Admin
- Posts: 10344
- Joined: Mon Mar 10, 2008 9:44 pm
A question about filling a region with colour and pattern
Hi Kent!
A classic way is using
Stefan
A classic way is using
\clip
in a scope
for defining the boundary and then \filldraw
. Not so easy this time, when I quickly tested it, but I may find a way later today.Stefan
LaTeX.org admin
A question about filling a region with colour and pattern
Actually I needed to filldraw a region with a somewhat simpler boundary. Se the new attached PDF file.
The region to be shaded is between the two parabola segments in red and the red line.
The region to be shaded is between the two parabola segments in red and the red line.
- Attachments
-
- latexforum2.pdf
- (3.55 KiB) Downloaded 377 times
A question about filling a region with colour and pattern
I like somebody to revisit this challenge for me. I have tried with no success after I got help from Stefan on a similar problem recently (posted on Nov. 2nd).
Kent
Kent
- Stefan Kottwitz
- Site Admin
- Posts: 10344
- Joined: Mon Mar 10, 2008 9:44 pm
A question about filling a region with colour and pattern
If we cannot easily use a single clip path since it's difficult with parabolas, we could clip several times. Each time, we define a clip path using a parabola, plus a few straight lines around the rest. Clipping all means getting the intersection area that's common to all parts, bounded by a parabola each (plus some straight lines).
This is quickly made
using parabolas and some simply chosen points. You can comment out all except one clip to see each area.
Minimal example for testing:
Stefan
This is quickly made

Code: Select all
\begin{scope}
\clip (O) parabola (P) -- (P2) -- (P1) -- ++(0,-2);
\clip (P1) parabola (P2) -- (P) -- (0,-4) -- (O) -- ++(-3,-4);
\clip (O) parabola (P1) -- (P2) -- (P) -- (-4,-4) ;
\clip (P2) parabola (P) -- (0,-5) -- (O) -- ++(0,-4) -- (P1);
\filldraw [red] (O) circle (20);
\end{scope}
Code: Select all
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[rotate=-90]
\coordinate (O) at (0,0);
\coordinate (S) at (-2,2);
\coordinate (P) at (-4,4);
\coordinate (P1) at (2,1);
\coordinate (P2) at (-1,5/2);
\draw[black,thick] (0,0) parabola (5,25/4);
\draw[black,thick] (0,0) parabola (-5,25/4);
\draw[black,thick] (-2,2) parabola (-5,6.5);
\draw[black,thick] (-2,2) parabola (1,6.5);
\draw[red,ultra thick] (O) parabola (P);
\draw[red,ultra thick] (O) parabola (P1);
\draw[red,ultra thick] (S) parabola (P);
\draw[red,ultra thick] (S) parabola (P2);
\draw[red,ultra thick] (P1) parabola (P2);
\begin{scope}
\clip (O) parabola (P) -- (P2) -- (P1) -- ++(0,-2);
\clip (P1) parabola (P2) -- (P) -- (0,-4) -- (O) -- ++(-3,-4);
\clip (O) parabola (P1) -- (P2) -- (P) -- (-4,-4) ;
\clip (P2) parabola (P) -- (0,-5) -- (O) -- ++(0,-4) -- (P1);
\filldraw [red] (O) circle (20);
\end{scope}
\end{tikzpicture}
\end{document}
LaTeX.org admin
A question about filling a region with colour and pattern
Thanks!
I finally succeeded in getting what my figure should really like, see the attached file.
Kent
I finally succeeded in getting what my figure should really like, see the attached file.

Kent
- Attachments
-
- figure.pdf
- (7.76 KiB) Downloaded 404 times
- Stefan Kottwitz
- Site Admin
- Posts: 10344
- Joined: Mon Mar 10, 2008 9:44 pm
A question about filling a region with colour and pattern
Great!
Would you like to add this as example to the TikZ gallery on TeXample.net? If yes, you could post the full code here.
What I see as a good point for learners, is filling an area made by several different curves by intersecting clipping areas.
Stefan
Would you like to add this as example to the TikZ gallery on TeXample.net? If yes, you could post the full code here.
What I see as a good point for learners, is filling an area made by several different curves by intersecting clipping areas.
Stefan
LaTeX.org admin
A question about filling a region with colour and pattern
Dear Stefan, if you think the figure has some learning potential, I will consider posting it at the Tikz gallery.
However, looking at some examples I see that people document their examples excellently.
My source code, I am afraid, is a little too obscure for others to read without extensive editing. It was intended only for me to read. (Among other things, I am using several private written macros not directly related to the issue of region shading we want to highlight.)
I am soon finally getting access to upgrade my PGF version to PGF 3.0. After that I will update the code and come back to you on this issue.
Best regards,
Kent
However, looking at some examples I see that people document their examples excellently.
My source code, I am afraid, is a little too obscure for others to read without extensive editing. It was intended only for me to read. (Among other things, I am using several private written macros not directly related to the issue of region shading we want to highlight.)
I am soon finally getting access to upgrade my PGF version to PGF 3.0. After that I will update the code and come back to you on this issue.
Best regards,
Kent