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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

At the risk of asking YET ANOTHER TIKZ question on a general TeX forum :), I was wondering if there was any easy way to draw a ruled surface like a hyperbolic paraboloid in TikZ? I'm not particular about the surface per se: I just need some eye candy for a nontrivial looking surface, and the hyperbolic paraboloid is a good example because of the negative curvature. I checked texample.net and google, and while I found a PSTricks package that can do this, it doesn't fit my workflow with pdflatex and Beamer.

share|improve this question
I often work with pdflatex and beamer and pstricks ... – Herbert Jun 5 '11 at 6:10
I'm sure that's possible. But my learning curve for tikz is already steep enough, with enough time invested, that I don't want to learn pstricks as well – Suresh Jun 5 '11 at 6:24
It was you who said "it doesn't fit my workflow with pdflatex and Beamer" ... – Herbert Jun 5 '11 at 6:58
Well wouldn't it be easier to draw that in sth like Mathematica, or Python and export it to .eps, or some other convenient program? – dingo_d Jun 5 '11 at 7:08
Easy no ! You can give a look at the package : tikz-3dplot. This is a case where pstricks and postcript are very strong. Herbert is right but you need to use something like pdftricks and you can give a look at the package pst-pdf – Alain Matthes Jun 5 '11 at 7:14
up vote 12 down vote accepted

PGFplots can do a reasonably good job with not too complex 3D plots. Here's an example of a hyperbolic paraboloid:


\addplot3 [surf,shader=flat,draw=black] {x^2-y^2};

hyperbolic paraboloid with PGFplots

share|improve this answer
ah ! I forgot pgfplots! :( perhaps pgfplots combines with gnuplot is a good solution ? – Alain Matthes Jun 5 '11 at 9:19
ah very nice. and I see from the manual that I can even get rid of axes etc. – Suresh Jun 5 '11 at 20:42
accepted this one because this is what I ended up using. But other answers are excellent too. – Suresh Jun 6 '11 at 6:15

Just because it is fun (I don't claim that this is a good way to draw this), using the fact that the surface is ruled):






    \draw[->] (0,0) -- (1,0,0);
    \draw[->] (0,0) -- (0,1,0);
    \draw[->] (0,0) -- (0,0,1);
    \foreach \n in {0,1,...,\steps} {
        \draw[ultra thick,color={startcolor!\i!endcolor}]
            ($(\lineAstart)!{\n/\steps}!(\lineAend)$) --


hyperbolic paraboloid

More interestingly, one can draw the two families of lines:




    \coordinate (lineAstart) at (1,0,1);
    \coordinate (lineAend) at (0,0,0);
    \coordinate (lineBstart) at (1,1,0);
    \coordinate (lineBend) at (0,1,1);

    \draw[->] (0,0) -- (1,0,0);
    \draw[->] (0,0) -- (0,1,0);
    \draw[->] (0,0) -- (0,0,1);

    % Draw the first family of lines

    \draw[name path global={f1l0},name path global={f1l0-short},f1] (lineAstart) -- (lineBstart);

    \foreach \n in {1,...,\steps} {

        % Create the path of the lines
        \edef\optname{name path global={f1l\n}}
            ($(lineAstart)!{\n/\steps}!(lineAend)$) --
        % Draw the correct bits of the lines
        \edef\optname{name intersections={of={f1l\n} and f1l\p},name path global={f1l\n-short}}
            (intersection-1) -- ($(lineBstart)!{\n/\steps}!(lineBend)$);
        \edef\optname{name intersections={of={f1l\n} and f1l0}}
            ($(lineAstart)!{\n/\steps}!(lineAend)$) -- (intersection-1);

    % Draw the second family of lines

    \foreach \n in {\steps,...,0} {

        % Create the paths
        \edef\optname{name path global={f2l\n}}
        \expandafter\path\expandafter[\optname,shorten <=4pt]
            ($(lineAstart)!{\n/\steps}!(lineBstart)$) --

        % Draw the correct bits
        \ifnum\n=\steps % handle the first line separately
            \draw[f2] (lineBstart) -- (lineBend);
            % Note: one should actually find the intersection with the correct line of the first family.
            % However, this is rather complicated. The following gives a good approximation when the
            % number of lines is high enough.
            \edef\optname{name intersections={of={f2l\n} and f2l\p,total=\noexpand\total}}
                   ($(lineAstart)!{\n/\steps}!(lineBstart)$) -- (intersection-1);
                    ($(lineAstart)!{\n/\steps}!(lineBstart)$) -- ($(lineAend)!{\n/\steps}!(lineBend)$);


hyperbolic paraboloid

Or combine the the pictures:

hyperbolic paraboloid

share|improve this answer
+1! You're right, that is fun! And it's quite a bit faster than PGFplots (if much less flexible). – Jake Jun 5 '11 at 17:56
oh that's really nice ! – Suresh Jun 5 '11 at 20:41

Using class beamer and running it with xelatex to get directly a pdf. It shows a 2D view of 3D curves in the x-y plane.


       viewpoint=50 30 25 rtp2xyz,Decran=50,lightsrc=viewpoint}
\psSolid[ngrid=.3 .3,object=grille,base=1.5 6.5 1.5 6.5,
\psPoint(4,4,4 5 sub 2 exp 4 5 sub 2 exp sub 6 div 5 add){P}
\psSurface[ngrid=.3 .3,fillcolor=green!30,incolor=gray!30,intersectiontype=0,
    [0 0 1 -6.5]
    [0 0 1 -6.1]
    [0 0 1 -5.7]
    [0 0 1 -5.3]
    [0 0 1 -4.9]},intersectioncolor=(bleu),intersectionlinewidth=1,
  linewidth=0.4pt,algebraic](1.5,1.5)(6.5,6.5){ ((y-5)^2-(x-5)^2)/6+5 }
\psPoint(2,6.5,6.5 5 sub 2 exp 2 5 sub 2 exp sub 6 div 5 add){S}\uput[0](S){$S$}
%% Contouring on xy plane for z=6.5 6.1 5.7 5.3 4.9
%% Explicit representation: z=((y-5)2-(x-5)2)/6+5
%% Parametric representation of z=f(x,y)
%% x=x(x)=x
%% y=y(x)=sqrt((x-5)^2+6*(z-5))+5
%% z=z(x)=0
\psSolid[range=3.155 6.5]
\psSolid[range=2.6 6.5]
\psSolid[range=2.15 6.5]
\psSolid[range=1.75 6.5]
\psSolid[range=4.35 5.7]
\psSolid[range=1.6 6.5]
\psSolid[range=3.7 6.3]

enter image description here

share|improve this answer
@Herbert xelatex takes the same way that latex : dvi ps and pdf ?because if you can run pstricks directly, i think its because xelatex uses dvi and then ps? isn't it ? – Alain Matthes Jun 5 '11 at 9:24
I have tried it, apparently xelatex runs slower than latex->dvips->ps2pdf. – xport Jun 5 '11 at 12:51
xelatex is always slower ... same for lualatex. The new features are not available for free ... – Herbert Jun 5 '11 at 12:55
... but they are worth it (imo). – Caramdir Jun 5 '11 at 16:23
Nice picture: I could use xelatex on my file and then this would be usable. – Suresh Jun 5 '11 at 20:42

Your Answer


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.