20

I'm trying to plot a function of the form $z(r,\theta)$ where $r \in [0, R]$ for a finite R, $\theta \in [0,2\pi[$, and z is the third coordinate, a function of the first two. I couldn't find anything to do it natively, so I went back to Cartesian coordinates. But the result does not satisfy me, because the range of x is a function of y, a consequence of the constraint $ x^2+y^2 < R^2$. Is there already something in Mathematica to handle this kind of plot?

user64494
  • 26,149
  • 4
  • 27
  • 56
Learning is a mess
  • 501
  • 1
  • 3
  • 9
  • 2
    Have you tried RevolutionPlot3D? – Cassini Feb 05 '13 at 14:59
  • @David That's a nice idea when $z$ is independent of $\theta$, but how do you propose using RevolutionPlot3D when $z$ does vary with $\theta$? – whuber Feb 05 '13 at 16:26
  • @whuber: Of course you're right. I didn't read the question too carefully. – Cassini Feb 05 '13 at 20:49
  • 1
    @whuber, you can still use RevolutionPlot[] for the purpose. Witness for instance RevolutionPlot3D[r^2 Cos[3 t], {r, 0, 1}, {t, 0, 3 π/2}]. Of course, it's more enlightening to use ParametricPlot3D[] instead, as in your answer. – J. M.'s missing motivation Feb 07 '13 at 03:12

2 Answers2

31

Do it parametrically. Here's a generic implementation:

cylinderPlot3D[f_, {rMin_, rMax_}, {tMin_, tMax_}, opts___] := 
   ParametricPlot3D[{r Cos[t], r Sin[t], f[r, t]}, {r, rMin, rMax}, {t, tMin, tMax}, opts]

For example,

f[r_, t_] := r^2 Cos[3 t];
cylinderPlot3D[f, {0, 1}, {0, 2 Pi}, Mesh->None, Boxed->False]

Figure

Mark Adler
  • 4,949
  • 1
  • 22
  • 37
whuber
  • 20,544
  • 2
  • 59
  • 111
10

Use

RevolutionPlot3D[ f[r,t], {r, rmax, rmin}, {t, tmax, tmin}]
Artes
  • 57,212
  • 12
  • 157
  • 245
user10409
  • 101
  • 1
  • 2