# Surface of Revolution

how to draw using surface of revolution tikz or pgfplots?

\documentclass{article}
\usepackage{tikz,pgfplots}

\begin{document}
\begin{tikzpicture}

\end{tikzpicture}
\end{document}


I am not able to reproduce a surface like this. Can anyone help me?

-
You should open a new question for this, instead of changing your existing one and unaccepting the answer. – Jake Nov 11 '11 at 0:29
Adding to the comment by @Jake, in the new question you should at least make an attempt in adapting the solution below to this new problem as they are clearly related. – Peter Grill Nov 11 '11 at 0:34

In the plots below I've given two demonstrations: one is a surface rotated around the y-axis, and one is rotated around the x-axis

The main trick is to parametrize the surface appropriately using the sine and cosine functions.

When you rotate the function f(t) around the y-axis, then you let

x(t,s) = t*cos(s)
y(t,s) = t*sin(s)
z(t,s) = f(t)


If you want to rotate the function f(t) around the x-axis, then you let

x(t,s) = t
y(t,s) = f(t)*cos(s)
z(t,s) = f(t)*sin(s)


Typically s will be on the interval [0,2\pi], and you can choose your interval for t as you like.

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

% rotated around the y-axis
\begin{tikzpicture}
\begin{axis}[view={60}{30}]
samples=20,
domain=1:2,y domain=0:2*pi,
z buffer=sort]
({x * cos(deg(y))}, {x * sin(deg(y))}, {1/x});
\end{axis}
\end{tikzpicture}

% rotated around the x-axis
\begin{tikzpicture}
\begin{axis}[view={60}{30}]
samples=20,
domain=1:2,y domain=0:2*pi,
z buffer=sort]
(x,{(1/x) * cos(deg(y))}, {(1/x) * sin(deg(y))});
\end{axis}
\end{tikzpicture}

\end{document}


Following the question edit

\begin{tikzpicture}
\begin{axis}[view={60}{30}]

@RegisdaSilva: You're welcome; you can tweak some further options such as label, perhaps even transparency, but this code gives the main idea :) – cmhughes Nov 10 '11 at 4:07
Update: recent versions of pgfplots allow to use builtin coordinate systems. A good extension to this answer could be to rely on data cs=polarrad and specify the input coordinates in the coordinate system <angle>,<radius>,<Z> . See also tex.stackexchange.com/questions/173602/… for another application – Christian Feuersänger Apr 28 '14 at 21:29