# pgfplots quadrics

I wonder whether it is possible to draw the three following quadric surfaces (cone, hyperboloids)

x^2+y^2-z^2=0

x^2+y^2-z^2=1

x^2+y^2-z^2=-1

(and the axis)


using pgfplots 3d or TikZ as it is done in the following image

-
Welcome to LaTeX! Hi Brownian and welcome to TeX.sx. In its current form, your question might not receive many answers. Please take a look at the How to Ask-page and try to improve your question according to the guidance found there. This may require you to show some effort on your part in terms of attempting a solution. If you have questions about what to do or if you don't quite understand what this means, please ask for clarification using the add comment function. –  percusse Aug 9 '12 at 22:15

## 2 Answers

Yes, it is certainly possible

Explanation

When working with such surfaces, you have at least two choices:

• work with the surfaces explicitly
• work with the surfaces parametrically

If you work with the surfaces explicitly, then for your first surface

x^2+y^2-z^2=0


you end up using something like

which is pretty ugly. Instead, if you parameterize it using polar coordinates, then you get

which is much more elegant. You can apply this same approach for each of your other surfaces.

Code

The only thing to note about the code below is that instead of using r and theta, I've used x and y; it might be possible to change this- see the documentation for details.

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
xmin=-3,xmax=3,
ymin=-3,ymax=3,
zmin=-2,zmax=2,
xlabel={$x$},
ylabel={$y$},
zlabel={$z$},
zlabel style={rotate=90},
view={60}{40}]
% x^2+y^2-z^2=0
\addplot3[mesh,black,domain=0:2,y domain=0:2*pi]({x*cos(deg(y))},{x*sin(deg(y))},{x});
\addplot3[mesh,black,domain=0:2,y domain=0:2*pi]({x*cos(deg(y))},{x*sin(deg(y))},{-x});
% x^2+y^2-z^2=-1
\addplot3[mesh,blue,domain=0:2,y domain=0:2*pi]({x*cos(deg(y))},{x*sin(deg(y))},{sqrt(x^2+1)});
\addplot3[mesh,blue,domain=0:2,y domain=0:2*pi]({x*cos(deg(y))},{x*sin(deg(y))},{-sqrt(x^2+1)});
% x^2+y^2-z^2=1
\addplot3[mesh,green,domain=1:2,y domain=0:2*pi,samples=15]({x*cos(deg(y))},{x*sin(deg(y))},{sqrt(x^2-1)});
\addplot3[mesh,green,domain=1:2,y domain=0:2*pi,samples=15]({x*cos(deg(y))},{x*sin(deg(y))},{-sqrt(x^2-1)});
\end{axis}
\end{tikzpicture}
\end{document}

-

run it with xelatex

\documentclass{article}
\usepackage{pst-solides3d}
\begin{document}

\psset{unit=0.8,viewpoint=50 60 30 rtp2xyz,Decran=50,lightsrc=viewpoint,
ngrid=20 20, incolor=red!30, fillcolor=blue!30}
\begin{pspicture}(-4,-4)(4,4)
\defFunction[algebraic]{f1}(u,v){u*cos(v)}{u*sin(v)}{u}
\defFunction[algebraic]{f3}(u,v){u*cos(v)}{u*sin(v)}{sqrt(u^2+1)}
\defFunction[algebraic]{f4}(u,v){u*cos(v)}{u*sin(v)}{-sqrt(u^2+1)}
\defFunction[algebraic]{f5}(u,v){u*cos(v)}{u*sin(v)}{sqrt(u^2-1)}
\defFunction[algebraic]{f6}(u,v){u*cos(v)}{u*sin(v)}{-sqrt(u^2-1)}
\psSolid[object=surfaceparametree,base=-4 4 pi pi neg,function=f1]
\psSolid[object=surfaceparametree,function=f4,base=-1 4 pi pi neg,opacity=0.4]
\psSolid[object=surfaceparametree,function=f3,opacity=0.4]
\psSolid[object=surfaceparametree,function=f6,base=1 4 pi pi neg,
fillcolor=red!30,incolor=blue!30,opacity=0.2]
\psSolid[object=surfaceparametree,function=f5,base=1 4 pi pi neg,opacity=0.2]
\gridIIID[Zmin=-4,Zmax=4](-4,4)(-4,4)
\end{pspicture}

\end{document}


or with viewpoint=50 60 10 rtp2xyz:

-
Although the OP asked specifically about PGF, I want to thank you for an amazing image! BTW: Where does the need for XeLaTeX arise? –  Dror Aug 10 '12 at 6:41
@Dror: Maybe it is the simplest compilation method among others such as pdflatex --shell-escape with \usepackage[pdf]{pstricks} or latex->dvips->ps2pdf combo. –  Please don't touch Aug 10 '12 at 7:22
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.6988893747329712, "perplexity": 2042.093394138207}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": false}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-23/segments/1406510266894.52/warc/CC-MAIN-20140728011746-00044-ip-10-146-231-18.ec2.internal.warc.gz"}