Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The documentation for RevolutionPlot3D shows that you can specify a parametric curve like this:

RevolutionPlot3D[{u, u}, {u, 0, 1}]

Mathematica graphics

I'd like to do this with a Piecewise function for {fx,fz}:

RevolutionPlot3D[Piecewise[{{{u, u}, u < 0.5}, {{u, 0.5}, u >= 0.5}}], {u, 0,

but I get messages and a blank plot:

Dot::rect: Nonrectangular tensor encountered.

Mathematica graphics

whereas a Piecewise function for {fx,fz} works in ParametricPlot, for example:

ParametricPlot[Piecewise[{{{u, u}, u < 0.5}, {{u, 0.5}, u >= 0.5}}], {u, 0, 1}]

Mathematica graphics

By writing Piecewise expressions for fx and fz separately, it works:

RevolutionPlot3D[{Piecewise[{{u, u < 0.5}, {u, u >= 0.5}}], 
    Piecewise[{{u, u < 0.5}, {0.5, u >= 0.5}}]}, {u, 0, 1}]

Mathematica graphics

How is it possible to piece together a function for {fx,fz} in RevolutionPlot3D?

share|improve this question
Interesting... RevolutionPlot3D[Function[t, {t, t}][u], {u, 0, 1}] doesn't work either. – J. M. Jul 12 '12 at 15:44
You could try RevolutionPlot3D[Evaluate[cone[u]], {u, 0, 1}]. – Heike Jul 12 '12 at 15:46
Thanks @Heike. Indeed, it turns out my toy example was too simple for the problem I have, which involves a Piecewise function. I'm going to update the question. – JxB Jul 12 '12 at 15:55
@J.M. I've updated the question example using Piecewise, which was my actual problem. It's probably related to the example in your comment. – JxB Jul 12 '12 at 16:10
Hmm, RevolutionPlot3D[Evaluate[Boole[u < 0.5] {u, u} + Boole[u >= 0.5] {u, 0.5}], {u, 0, 1}] works well (using Heike's suggestion); if you remove the Evaluate[], it fails. Very peculiar... – J. M. Jul 12 '12 at 16:15
up vote 7 down vote accepted

As stated in the first note under More Information of the documentation, the form RevolutionPlot3D[fz,{t,...}] is short form for RevolutionPlot3D[{t,0,fz},{t,...}].

To invoke the form you want, you need to call RevolutionPlot3D with a list of two elements, avoiding triggering the short form above:

pw[u_] := Piecewise[{{{u, u}, u < 0.5}, {{u, 0.5}, u >= 0.5}}]

RevolutionPlot3D[{pw[u][[1]], pw[u][[2]]}, {u, 0, 1}]

enter image description here

This misses that there is a discontinuity at 0.5, so it does not exclude it from the plot. You can get the original plot by adding Exclusions -> {u == 0.5}:

RevolutionPlot3D[{pw[u][[1]], pw[u][[2]]}, {u, 0, 1}, Exclusions -> {u == 0.5}]

enter image description here

Update per comment from J. M.:

Evaluate[Boole[u < 0.5] {u, u} + Boole[u >= 0.5] {u, 0.5}]

works as well, because it evaluates to:

{u Boole[u >= 0.5] + u Boole[u < 0.5], 0.5 Boole[u >= 0.5] + u Boole[u < 0.5]}

This does detect the discontinuity, but of course has the drawback that the input had to be rewritten from a Piecewise:

RevolutionPlot3D[Evaluate[Boole[u < 0.5] {u, u} + Boole[u >= 0.5] {u, 0.5}], {u, 0, 1}]

enter image description here

share|improve this answer
That precludes constructions like RevolutionPlot3D[BSplineFunction[{{1, 1}, {2, 3}, {3, -1}, {4, 1}, {5, 0}}][u], {u, 0, 1}], I guess. – J. M. Jul 12 '12 at 16:31
Your input won't work directly, but there is nothing stopping you from defining a bspl[u_]:=BSplineFunction[...] and then calling the plot similar as with pw in my answer. – Malte Lenz Jul 12 '12 at 16:34
Interestingly, my plot also has problems with the discontinuity. – JxB Jul 12 '12 at 16:40
Turns out it purposefully excludes it. If you want it filled, you can add Exclusions -> None to the plot call. My version is a black box to the plot function, so it does not detect the discontinuity. (Edited answer to reflect this.) – Malte Lenz Jul 12 '12 at 16:44

Your Answer


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.