[Tex/LaTex] Surface of Revolution

graphicspgfplotstikz-pgf

enter image description herehow 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?
enter image description here

Best Answer

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.

screenshot

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

% rotated around the y-axis
\begin{tikzpicture}
 \begin{axis}[view={60}{30}]
  \addplot3[surf,shader=flat,
  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}]
  \addplot3[surf,shader=flat,
  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

enter image description here

\begin{tikzpicture}
 \begin{axis}[view={60}{30}]
  \addplot3[surf,shader=flat,
  samples=20,
  domain=0:2*pi,y domain=0:2*pi,
  z buffer=sort]
  ({x * cos(deg(y))}, {x * sin(deg(y))}, {cos(deg(x))});
 \end{axis}
\end{tikzpicture}