LaTeX forum ⇒ Graphics, Figures & TablesFilling for a custom Area Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
User avatar
Bozack
Posts: 115
Joined: Wed Feb 06, 2008 4:21 pm

Filling for a custom Area

Postby Bozack » Fri Jun 28, 2013 11:07 pm

I'm quite new to TikZ, and am trying to make a simple shape and fill it in with a color. As far as I understand, I can simply make a path, draw all the lines and curves, and then fill them as in the example code below:

  1. \documentclass[11pt]{article}
  2. \usepackage{tikz}
  3.  
  4. \begin{document}
  5. \begin{tikzpicture}
  6. \path [fill=Red, draw=Black, line width=1mm]
  7. (1.34,-3.95) -- (4.36,-1.51)
  8. arc [radius=3.77, start angle=201.24007, end angle=302.93512]
  9. (9.92,-3.33) -- (8.96,-2.69) -- (12.56,-1.37) -- (12.58,-5.09) -- (11.48,-4.35)
  10. arc [radius=6.57, start angle=318.5605, end angle=217.13745];
  11. \end{tikzpicture}
  12. \end{document}

However, this results in a less than satisfactory result (see attachment). There is this weird line from the starting point to somewhere in the "pointy" end of the figure. Can you see what is wrong? :(
Attachments
result.png
result.png (7.82 KiB) Viewed 7490 times
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 7 Professional 64bit, MikTeX 2.9, TeXnicCenter 2.0 beta 1 64bit

Tags:

Klausiber
Posts: 16
Joined: Sun Apr 14, 2013 11:41 pm

Postby Klausiber » Wed Jul 03, 2013 3:13 pm

Bozack wrote:As far as I understand, I can simply make a path, draw all the lines and curves, and then fill them as in the example code below
[...]
There is this weird line from the starting point to somewhere in the "pointy" end of the figure. Can you see what is wrong? :(

There are two things that contribute to your problem:

Whenever you tell TikZ to fill a path, this path needs to be closed, i.e. it must end at its starting point. When it does not, TikZ closes the path for you - this is the line you see.

Now you may wonder why your path is not closed and especially why the "closing line" starts after the first arc. The problem is the move-to operation you use there. The arc already ends in a point and yet you tell TikZ to move to another point (9.92,-3.33) - although this happens to be the same physical spot in this case - because you give it no line-to operation. This ends the path and starts a new one. I have no idea why the final filling operation works none the less.

Also note, that in your picture there's an ugly line joint at this very point. Maybe zoom in to see it better. This also indicates that TikZ does not see this a continued path as it would join the lines properly in this case. Have a look at the lower arc for reference.

Here's a corrected version:
  1. \documentclass[11pt]{article}
  2. \usepackage{tikz}
  3.  
  4. \begin{document}
  5. \begin{tikzpicture}
  6. \path [draw=black, fill=red, line width=1mm]
  7. (4.36,-1.51) arc [radius=3.77, start angle=201.24007, end angle=302.93512]
  8. -- (8.96,-2.69) -- (12.56,-1.37) -- (12.58,-5.09) -- (11.48,-4.35)
  9. arc [radius=6.57, start angle=318.5605, end angle=217.13745] -- cycle;
  10. \end{tikzpicture}
  11. \end{document}

User avatar
Bozack
Posts: 115
Joined: Wed Feb 06, 2008 4:21 pm

Postby Bozack » Wed Jul 03, 2013 6:11 pm

Klausiber wrote:... you may wonder why your path is not closed and espacially why the "closing line" starts after the first arc. The problem is the move-to operation you use there. The arc already ends in a point and yet you tell TikZ to move to another point (9.92,-3.33) - although this happens to be the same physical spot in this case - because you give it no line-to operation. This ends the path and starts a new one.

Thank you so much for that solution, now I understand! :)
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 7 Professional 64bit, MikTeX 2.9, TeXnicCenter 2.0 beta 1 64bit


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Baidu [Spider] and 3 guests