## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ A question about filling a region with colour and pattern Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
kent
Posts: 39
Joined: Thu Oct 20, 2016 3:41 pm

### 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
Attachments
latexforum2.pdf
latexforum2.tex

Stefan Kottwitz
Posts: 8596
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Hi Kent!

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

kent
Posts: 39
Joined: Thu Oct 20, 2016 3:41 pm
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.
Attachments
latexforum2.pdf

kent
Posts: 39
Joined: Thu Oct 20, 2016 3:41 pm
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

Stefan Kottwitz
Posts: 8596
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
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.

\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}

parabola-intersection-fill.png (10.38 KiB) Viewed 378 times

Minimal example for testing:

\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}

Stefan

kent
Posts: 39
Joined: Thu Oct 20, 2016 3:41 pm
Thanks!
I finally succeeded in getting what my figure should really like, see the attached file.
Kent
Attachments
figure.pdf

Stefan Kottwitz
Posts: 8596
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
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

kent
Posts: 39
Joined: Thu Oct 20, 2016 3:41 pm
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