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

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

A question about filling a region with colour and pattern

Postby kent » Fri Jun 02, 2017 1:35 pm

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
(3.55 KiB) Downloaded 18 times
latexforum2.tex
(1.63 KiB) Downloaded 17 times

User avatar
Stefan Kottwitz
Site Admin
Posts: 8453
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Fri Jun 02, 2017 2:35 pm

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
Site admin

kent
Posts: 28
Joined: Thu Oct 20, 2016 3:41 pm

Postby kent » Mon Jun 05, 2017 3:10 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
(3.55 KiB) Downloaded 19 times

kent
Posts: 28
Joined: Thu Oct 20, 2016 3:41 pm

Postby kent » Tue Nov 07, 2017 12:22 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

User avatar
Stefan Kottwitz
Site Admin
Posts: 8453
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Tue Nov 07, 2017 5:21 pm

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.

  1. \begin{scope}
  2. \clip (O) parabola (P) -- (P2) -- (P1) -- ++(0,-2);
  3. \clip (P1) parabola (P2) -- (P) -- (0,-4) -- (O) -- ++(-3,-4);
  4. \clip (O) parabola (P1) -- (P2) -- (P) -- (-4,-4) ;
  5. \clip (P2) parabola (P) -- (0,-5) -- (O) -- ++(0,-4) -- (P1);
  6. \filldraw [red] (O) circle (20);
  7. \end{scope}


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


Minimal example for testing:

  1. \documentclass[border=10pt]{standalone}
  2. \usepackage{tikz}
  3. \begin{document}
  4. \begin{tikzpicture}[rotate=-90]
  5. \coordinate (O) at (0,0);
  6. \coordinate (S) at (-2,2);
  7. \coordinate (P) at (-4,4);
  8. \coordinate (P1) at (2,1);
  9. \coordinate (P2) at (-1,5/2);
  10. \draw[black,thick] (0,0) parabola (5,25/4);
  11. \draw[black,thick] (0,0) parabola (-5,25/4);
  12. \draw[black,thick] (-2,2) parabola (-5,6.5);
  13. \draw[black,thick] (-2,2) parabola (1,6.5);
  14. \draw[red,ultra thick] (O) parabola (P);
  15. \draw[red,ultra thick] (O) parabola (P1);
  16. \draw[red,ultra thick] (S) parabola (P);
  17. \draw[red,ultra thick] (S) parabola (P2);
  18. \draw[red,ultra thick] (P1) parabola (P2);
  19. \begin{scope}
  20. \clip (O) parabola (P) -- (P2) -- (P1) -- ++(0,-2);
  21. \clip (P1) parabola (P2) -- (P) -- (0,-4) -- (O) -- ++(-3,-4);
  22. \clip (O) parabola (P1) -- (P2) -- (P) -- (-4,-4) ;
  23. \clip (P2) parabola (P) -- (0,-5) -- (O) -- ++(0,-4) -- (P1);
  24. \filldraw [red] (O) circle (20);
  25. \end{scope}
  26. \end{tikzpicture}
  27. \end{document}


Stefan
Site admin

kent
Posts: 28
Joined: Thu Oct 20, 2016 3:41 pm

Postby kent » Thu Nov 09, 2017 2:19 pm

Thanks!
I finally succeeded in getting what my figure should really like, see the attached file. :)
Kent
Attachments
figure.pdf
(7.76 KiB) Downloaded 8 times

User avatar
Stefan Kottwitz
Site Admin
Posts: 8453
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Thu Nov 09, 2017 2:36 pm

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
Site admin

kent
Posts: 28
Joined: Thu Oct 20, 2016 3:41 pm

Postby kent » Mon Nov 13, 2017 12:48 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


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Bing [Bot] and 6 guests