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.

I'm interested in the hyperboloid u^2 + v^2 - w^2 = 1, which can be parameterized as

u = cosh(x) cos(y),
v = cosh(x) sin(y),
w = sinh(x).

This parameterization can be used to draw the hyperboloid in pgfplots as follows:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.6}

\begin{document}

\begin{tikzpicture}
 \begin{axis}
  \addplot3[surf,
            fill=white,
            samples=10,
            samples y=72,
            domain=-1:1,
            y domain=0:360,
            z buffer=sort]
            ( {cosh(x)*cos(y)}, {cosh(x)*sin(y)}, {sinh(x)} );
 \end{axis}
\end{tikzpicture}

\end{document}

That works beautifully, but now I would like to restrict the plot to, say, the region where v + w > 0. In terms of my (x,y) parameters this reads cosh(x) sin(y) + sinh(x) > 0. According to the PGFPlots manual I should be able to use the restrict expr to domain option to accomplish this, but when I try it I get a LaTeX error:

! Package PGF Math Error: Could not parse input '' as a floating point number, sorry. The unreadable part was near ''..

I'm assuming this option should be given at the \addplot3 level, not at the \begin{axis} level, but the error appears either way.

Actually what I would like to do is plot the hyperboloid twice; first, the full hyperboloid in a nice subdued gray, and then, on top of it, the region of interest in bright colors, so that it can actually be identified as part of the hyperboloid.


I'm providing an updated MWE since I guess the whole thing got a bit confusing with all the changing in variable names. Here's what I intended to do:

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
 \begin{axis}[view={120}{5},
              samples=20,
              samples y=72,
              domain=-2:2,
              y domain=0:360,
              z buffer=sort,
              variable=\u,
              variable y=\v]
  \addplot3[surf,
            restrict expr to domain={y+z}{0:100}]
            ( {cosh(u)*cos(v)}, {cosh(u)*sin(v)}, {sinh(u)} );
 \end{axis}
\end{tikzpicture}

\end{document}

With the unstable version of pgfplots installed, this draws only half of the hyperboloid---the half determined by the condition y + z > 0---, as expected.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

This is a bug in the current stable pgfplots 1.7 (sorry).

I have fixed it in the pgfplots unstable (available at http://pgfplots.sourceforge.net/).

Note that your example suffers from a usability issue in pgfplots: as soon as pgfplots has evaluated the parametric coordinates, it redefines x to be the resulting X coordinate and y to be the resulting Y coordinate. Thus, your example works if you switch to variable=u, variable y=w. Of course, you could also employ the usability issue and write restrict expr to domain={y + z}{0:99999}.

share|improve this answer
    
I'm a bit unsure as to what you mean by a "usability issue". Does it mean it is somehow more "efficient" for pgfplots if the parameters are called, e.g., (u,v) instead of (x,y)? This is actually easier for me, since my restrictions are given in terms of the Cartesian coordinates instead of the parameters. I tried variable=\u, variable y=\v and restrict expr to domain={y+z}{0:100}, but got the same error as above. Will it work if I install the unstable version from Sourceforge? –  nemarona Oct 31 '12 at 21:41
    
I try to clarify what I mean with "usability issue": pgfplots does not care about the variable names; and the efficiency will not change just by changing variable names. What I wanted to say is that end-users care about the names - and in your case, you have two variables x but their meaning is different: inside of the plot expression, it is the sampled variable and inside of the restrict to domain it is the resulting X coordinate. This disambiguity is confusing for any end-user (including me). That's what I call a usability issue: it is hard to use. –  Christian Feuersänger Nov 1 '12 at 8:17
    
Concerning the original problem: the only cure is to get an updated version of pgfplots. At the time of this writing, the unstable available on http://pgfplots.sourceforge.net/ is your best choice (and: yes, it fixes the issue). The second-best choice is the git version. If you do not want to install these downloads, you have to wait for the next stable version. –  Christian Feuersänger Nov 1 '12 at 8:19
    
It was indeed confusing for me too. With the unstable version installed, variable=\u, variable y=\v and restrict expr to domain={y+z}{0:100} now yield the expected result. Thank you! –  nemarona Nov 1 '12 at 14:42
    
Oops. Of course I should have written y+z instead of x+y - I misread your spec. Sorry –  Christian Feuersänger Nov 1 '12 at 16:22

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.