Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there a trick to fill the parametric plot of a catacaustic which looks closed but isn’t closed in TiKZ meaning. The Problem is the egdge which looks closed but isn’t it …

problem

I guess I can experiment with overlay a withe area or try to clip with a limited second plot using the even odd rule but I hope theres a more comfortable way to to this.

Code

% needs gnuplot
\documentclass{minimal}

\usepackage{tikz}
\tikzset{samples=500}

\begin{document}
\begin{tikzpicture}
    \draw [thick, fill=red] plot [id=op-12,parametric]
        function{2*cos(t)-cos(2*t),2*sin(t)-sin(2*t)};
    \draw [<-] (1.5,0) -- +(1.5,0) node [right] {Problem};
\end{tikzpicture}
\end{document}
share|improve this question

1 Answer 1

up vote 8 down vote accepted

Change the domain to 0:2*pi:

enter image description here

\documentclass{article}

\usepackage{tikz}
\tikzset{samples=500}

\begin{document}
\begin{tikzpicture}
    \draw [thick, fill=red,domain=0:2*pi] plot 
        ({2*cos(\x r)-cos(2*\x r)},{2*sin(\x r)-sin(2*\x r)});
\end{tikzpicture}
\end{document}

(I haven't used Gnuplot because it's not necessary here.)

share|improve this answer
1  
The simplicity of this is beautiful! Presumably the default domain is such that the path overruns and so when it is automatically closed (for the fill) then it joins the new endpoints which aren't where one might expect them to be. –  Loop Space Nov 5 '11 at 17:48
    
@Andrew: that's exactly what's happening as you can see by adding \draw ({2*cos(5 r)-cos(2*5 r)},{2*sin(5 r)-sin(2*5 r)}) -- ({2*cos(-5 r)-cos(2*-5 r)},{2*sin(-5 r)-sin(2*-5 r)}); to the code. –  Philippe Goutet Nov 5 '11 at 19:07
    
Thank you works fine even with gnuplot. Is there a reason to not use gnuplot if the internal machine is able to plot it? –  Tobi Nov 5 '11 at 22:59
    
@Tobi: if your system is configured to be able to use gnuplot, there's no real reason not to use it. But a code not using it is more portable as you're sure it will run everywhere. –  Philippe Goutet Nov 6 '11 at 15:06
    
OK, I knew that. But since I use many plots and the id= mechanism it should be portable to and I think the gnuplot function input is more readable than the on PGF needs. So I prefer using gnuplot :-) –  Tobi Nov 6 '11 at 15:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.