@Jake: this is the whole document

    \documentclass[11pt, a4paper]{book}



    \tikzset{x={(.965cm,-.258cm)}, y={(.7cm,.7cm)}, z={(0cm,1cm)},
    sezioni/.style={draw=#1!60, thin, fill=#1!30, fill opacity=0.3},
    \coordinate (O) at (0,0,0) node [left] {$O$};
    \draw[gray,->] (-2,0,0) -- (2,0,0) node [right, black] {$x$};
    \draw[gray, ->] (0,-2,0) -- (0,2,0) node [right, black] {$y$};
    \draw[gray, ->] (O) -- (0,0,3) node [left, black] {$z$};

    %=====% sezioni %=====%
    \foreach \x in {-1,-.85,...,1}
        \draw[sezioni=teal] (\x,{sqrt(1-(\x)^2)},0)--(\x,0,{sqrt(4*(1-(\x)^2))})--(\x,{-sqrt(1-(\x)^2)},0)--(\x,{sqrt(1-(\x)^2)},0);

    \draw[blue] (O) circle (1);
    \draw[red, domain=-1:1, samples=500] plot (\x,0,{sqrt(4*(1-(\x)^2))});


The red map in x=1 should produce the value zero, but it is positive.

  • 2
    Hi Lorenzo, welcome to the site! This is a known bug that's been fixed in the development version of PGF. There's a bugfix at the linked question. – Jake Feb 23 '13 at 10:40
  • A fine solution is to install gnuplot : \draw plot[id=f,domain=-1:1] function{sqrt(4*(1-x**2))}; – Alain Matthes Feb 23 '13 at 10:48
  • 1
    @Lorenzo: Actually, I take that back, the fix at the linked question works for 2^\x, but not for \x^2. You'll need to say (\x)^2 to get the correct plot. – Jake Feb 23 '13 at 10:50
  • 1
    @Lorenzo: I'm not sure I understand what you mean. What does it produce instead? Could you edit your question to include a screenshot of your output, and turn the code snippet into a complete minimal compilable document (starting from \documentclass)? – Jake Feb 23 '13 at 11:21
  • 1
    @Lorenzo: It may be compilable with every preamble, but it's generally preferred if full example documents are posted so it's easier to try the code out, and to rule out the possibility of any "side-effects" of packages that may be loaded. Note that you don't need to load color if you're loading tikz. If you have less than 10 rep, you can insert the picture and then remove the ! from the code, someone else will then edit the question to insert it back in. – Jake Feb 23 '13 at 14:06

This is due to a numerical inaccuracy when determining where to sample the function. The following code makes sure that the upper bound of the domain is always sampled:



    \draw (-2,0,0) -- (2,0,0);

    \draw[red, domain=-1:1, samples=50] plot (\x,{sqrt(4*(1-(\x)^2))});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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