# 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}


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}


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]
\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]
({x*cos(deg(y))},
{x*sin(deg(y))},
{x});
({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]