Re: Drawing Potatoes and a Problem with Piecewise

• To: mathgroup at smc.vnet.net
• Subject: [mg80146] Re: Drawing Potatoes and a Problem with Piecewise
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Tue, 14 Aug 2007 06:48:48 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <f9p580\$r58\$1@smc.vnet.net>

```David Park wrote:
> Several years ago there was a question on MathGroup on how to draw a potato
> in Mathematica.
>
> The SphericalDraw3D documentation has an example of a lumpy sphere and I
> decided to turn this into a potato by stretching it by a factor of two along
> the z axis. However, to get a reasonable looking potato it is necessary to
> damp down the variations in radius near the ends with a weighting function.
> So I constructed the following w weighting function using Piecewise.
>
> w[\[Theta]_] = Piecewise[
>   {{1/2 (\[Theta]/(\[Pi]/4))^3, 0 <= \[Theta] < \[Pi]/4},
>    {1 - 1/2 ((\[Pi]/2 - \[Theta])/(\[Pi]/4))^3, \[Pi]/
>       4 <= \[Theta] < \[Pi]/2},
>    {1 + 1/2 ((\[Pi]/2 - \[Theta])/(\[Pi]/4))^3, \[Pi]/2 <= \[Theta] <
>      3 \[Pi]/4},
>    {1/2 ((\[Pi] - \[Theta])/(\[Pi]/4))^3,
>     3 \[Pi]/4 <= \[Theta] <= \[Pi]}}]
> Plot[w[\[Theta]], {\[Theta], 0, \[Pi]}, PlotPoints -> 20,
>  Frame -> True]
>
> The problem with this is that there are gaps in the function, which are more
> or less visible depending on the number of PlotPoints. Am I defining
> Piecewise incorrectly, or is there a bug with Piecewise in plotting
> functions?
<snip>

David,

The definition of w is correct (w is continuous). However, the trouble
seems to come from the adaptive sampling, as we can see by evaluating
the following expressions:

Plot[ w[\[Theta]], { \[Theta], 0, Pi}, PlotPoints -> 45, Frame -> True,
MaxRecursion -> 15]

Plot[ w[\[Theta]], { \[Theta], 0, Pi}, PlotPoints -> 20, Frame -> True,
MaxRecursion -> 0]

Plot[ w[\[Theta]], { \[Theta], 0, Pi}, PlotPoints -> 20, Frame -> True]

On my system, the first expression draws a smooth curve, while plot
rendered by the second expression is cut on the left (but not on the
right). (The last expression is the original one for comparison.)

--
Jean-Marc

```

• Prev by Date: problem using Ersek's RootSearch
• Next by Date: Re: a problem about NDSolve and NIntegrate
• Previous by thread: Re: Drawing Potatoes and a Problem with Piecewise
• Next by thread: Graphing an inequality