7
$\begingroup$

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,
   1}]

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?

$\endgroup$
5
  • $\begingroup$ Interesting... RevolutionPlot3D[Function[t, {t, t}][u], {u, 0, 1}] doesn't work either. $\endgroup$ Jul 12, 2012 at 15:44
  • $\begingroup$ You could try RevolutionPlot3D[Evaluate[cone[u]], {u, 0, 1}]. $\endgroup$
    – Heike
    Jul 12, 2012 at 15:46
  • $\begingroup$ 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. $\endgroup$
    – JxB
    Jul 12, 2012 at 15:55
  • $\begingroup$ @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. $\endgroup$
    – JxB
    Jul 12, 2012 at 16:10
  • $\begingroup$ 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... $\endgroup$ Jul 12, 2012 at 16:15

1 Answer 1

9
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ That precludes constructions like RevolutionPlot3D[BSplineFunction[{{1, 1}, {2, 3}, {3, -1}, {4, 1}, {5, 0}}][u], {u, 0, 1}], I guess. $\endgroup$ Jul 12, 2012 at 16:31
  • $\begingroup$ 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. $\endgroup$
    – Malte Lenz
    Jul 12, 2012 at 16:34
  • $\begingroup$ Interestingly, my plot also has problems with the discontinuity. $\endgroup$
    – JxB
    Jul 12, 2012 at 16:40
  • $\begingroup$ 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.) $\endgroup$
    – Malte Lenz
    Jul 12, 2012 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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