# How to draw a circular cone

I want to draw the circular cone given by the equation z²=x²+y². (I do not mind using any given package.) I tried to use the pst-solides3d package with the help of its manual to generate the following code. However, my code produced only the axes. I received the following error messages (I am using TeXShop with XeLaTeX and "TeX and DVI" options selected to typeset):

** WARNING ** Image format conversion for PSTricks failed.
** WARNING ** Interpreting special command pst: (ps:) failed.

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

\psset{Decran=20}
\begin{pspicture}(-5,-5)(5,5)
\axesIIID(4,4,4)
\psSurface(0,0)(3,3){sqrt(x^2+y^2)}
\psSurface(-3,-3)(0,0){-sqrt(x^2+y^2)}
\end{pspicture}

\end{document}

-

## 3 Answers

PSTricks needs to know that you want to define your surface algebraically, and not using Reverse Polish Notation (RPN).

If you want to work algebraically, then you have to define the function first using \defFunction[algebraic]... as shown below.

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

\begin{document}

\psset{Decran=20}
\begin{pspicture}(-5,-5)(5,5)
\axesIIID(4,4,4)
\defFunction[algebraic]{cone}(x,y)
{x}
{y}
{sqrt(x^2+y^2)}
\defFunction[algebraic]{negcone}(x,y)
{x}
{y}
{-1*sqrt(x^2+y^2)}
\psSolid[object=surfaceparametree,base=0 3 0 3,
ngrid=20 20,
function=cone]
\psSolid[object=surfaceparametree,base=0 3 0 3,
ngrid=20 20,
function=negcone]
\end{pspicture}

\end{document}


For more information:

EDIT

Alternatively, you could follow the examples in Chapter 8 of the pst-solides3d documentation:

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

\begin{document}

\centering
\psset{unit=0.5,viewpoint=50 40 30 rtp2xyz}
\begin{pspicture}(-7,-8)(7,8)
\psSurface[ngrid=.25 .25,incolor=yellow,fillcolor=red,
algebraic](-4,-4)(4,4){sqrt(x^2+y^2)}
\psSurface[ngrid=.25 .25,incolor=yellow,fillcolor=blue,
axesboxed,algebraic,Zmin=-6,Zmax=6](-4,-4)(4,4){-1*sqrt(x^2+y^2)}
\end{pspicture}

\end{document}


-

You could also use pgfplots for this. To add a three dimensional surface, use \addplot3 [surf] {<expression for z>}. You could produce the cone using

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=-5:5,
y domain=-5:5,
xmin=-10,
xmax=10,
ymin=-10,
ymax=10,
restrict z to domain=-5:5]
\addplot3 [surf,shade=interp] {sqrt(x^2 + y^2};
\addplot3 [surf] {-sqrt(x^2 + y^2};
\end{axis}
\end{tikzpicture}

\end{document}


If you want the grid points to lie on isolines, you can use the syntax \addplot3 ({<x expression>}, {<y expression>}, {<z expression}); for parametric plots:

\begin{tikzpicture}
\begin{axis}[
domain=0:5,
y domain=0:2*pi,
xmin=-10,
xmax=10,
ymin=-10,
ymax=10,
samples=20]
\addplot3 [surf,z buffer=sort]
({x*cos(deg(y))},
{x*sin(deg(y))},
{x});
\addplot3 [surf,z buffer=sort]
({x*cos(deg(y))},
{x*sin(deg(y))},
{-x});
\end{axis}
\end{tikzpicture}


-

@jake and @ cmhughes: Thank you very much. Very nice. I appreciate it.

@cmhughes: I used your idea to parametrize the cone using polar parameters.

\documentclass{article}
\usepackage{pst-solides3d}
\usepackage{pst-3dplot}

\begin{document}

\psset{Decran=20, linecolor=gray}
\begin{pspicture}(-5,-5)(5,5)
\defFunction[algebraic]{cone}(r,t)
{r*cos(t)}
{r*sin(t)}
{r}
\psSolid[object=surfaceparametree,base=-3 3 0 360,
ngrid=36 60,
function=cone,incolor=white]
\axesIIID(4,4,5)
\end{pspicture}
\end{document}


@jake: I realized that you are using polar parameters already. A slightly simplified version is given below.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=-5:5,
y domain=0:2*pi,
xmin=-10,
xmax=10,
ymin=-10,
ymax=10,
samples=20]
\addplot3 [surf,z buffer=sort]
({x*cos(deg(y))},
{x*sin(deg(y))},
{x} );
\end{axis}
\end{tikzpicture}
\end{document}


-
You're right, thanks. – Jake Sep 18 '11 at 4:50
@Sony: You're welcome. I cropped your images. Don't forget to up-vote and accept whichever answer you deem most appropriate to your question. – cmhughes Sep 18 '11 at 15:09