[Tex/LaTex] tikz draw plot not correct

plottikz-pgf

I am trying to plot a naca0012 airfoil profile by its analytic function ( cf wikipedia ) using tikz and I can't understand why I get the following results. I precise that I get the same results if I use gnuplot in tikz \draw plot function. It seems to badly compute the 4 first percent of the plot. If I change to domain=0.:0.05, I also get the 4 first percent of domain=0.:0.05 wrong.

what am I wrong ? Should I specified a tikz option somehow ?

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=10]
  \draw[step=.02,gray,very thin] (-0.1,-0.1) grid (1.1,0.15);

  \draw[color=red,domain=0.:1.,scale=5] plot[id=naca] (\x,{0.12/0.2*(0.2969*sqrt(\x )-0.126*\x -0.3516*\x^2 +0.2843*\x^3 -0.1015*\x^4 )}) ;
  \draw[color=blue,domain=0.:.05,yshift=1] plot[id=naca] (\x,{0.12/0.2*(0.2969*sqrt(\x )-0.126*\x -0.3516*\x^2 +0.2843*\x^3 -0.1015*\x^4 )}) ;

\end{tikzpicture}

\end{document}

produces enter image description here

Best Answer

The plot is linear between sampling points. To reach a better resolution (and therefore make the plot smoother) use the samples option, i.e.

\draw[domain=0.:1.,samples=400] plot[id=naca] (\x,{0.12/0.2*(0.2969*sqrt(\x )-0.126*\x -0.3516*\x^2 +0.2843*\x^3 -0.1015*\x^4 )}) ; 

You can see the sampling points if you add the marks=+ (or * or x, if your prefer). To adjust for your scaling, the size of the markers need to be reduced.

\draw[domain=0.:1.,samples=100] plot[id=naca,mark=+,mark size=0.1] (\x,{0.12/0.2*(0.2969*sqrt(\x )-0.126*\x -0.3516*\x^2 +0.2843*\x^3 -0.1015*\x^4 )}) ;   

Also, instead of using a high sample count, you can supply smooth to get a better interpolation algorithm.

You may also want to look at the pgfplots package.