Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
6  
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
5  
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

1 Answer 1

up vote 24 down vote accepted

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}
share|improve this answer
    
Thanks cmhughes. –  Regis da Silva Nov 10 '11 at 4:06
    
@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
    
New help, please. –  Regis da Silva Nov 11 '11 at 0:22
9  
@RegisdaSilva I'm very happy to help, but it seems a little unfair to un-accept my answer now that you've changed the question. I did answer the original question. –  cmhughes Nov 11 '11 at 0:27
1  
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 at 21:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.