Drawing Potatoes and a Problem with Piecewise

• To: mathgroup at smc.vnet.net
• Subject: [mg80121] Drawing Potatoes and a Problem with Piecewise
• From: "David Park" <djmpark at comcast.net>
• Date: Mon, 13 Aug 2007 04:30:41 -0400 (EDT)

```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?

So I made another definition of a weighting function, w2, using Which, as
follows:

w2[\[Theta]_] =
Which[
0 <= \[Theta] < \[Pi]/4, (32 \[Theta]^3)/\[Pi]^3,
\[Pi]/4 <= \[Theta] < \[Pi]/2,
1 - (32 (\[Pi]/2 - \[Theta])^3)/\[Pi]^3,
\[Pi]/2 <= \[Theta] < (3 \[Pi])/4,
1 + (32 (\[Pi]/2 - \[Theta])^3)/\[Pi]^3,
(3 \[Pi])/4 <= \[Theta] <= \[Pi], (
32 (\[Pi] - \[Theta])^3)/\[Pi]^3]
Plot[w2[\[Theta]], {\[Theta], 0, \[Pi]}, PlotPoints -> 20,
Frame -> True]

This definition causes no problem in plotting. Here is the potato with the
two weighting functions. You can see that the w function leaves the potato
sliced into four pieces.

Table[Show[
Graphics3D[
First[SphericalPlot3D[
1 + f Sin[5 \[Phi]] Sin[11 \[Theta]]/20, {\[Theta], 0,
Pi}, {\[Phi], 0, 2 Pi},
PlotPoints -> {16, 25},
PlotStyle -> Darker@Brown,
Mesh -> None]] // Scale[#, {1, 1, 2}, {0, 0, 0}] &],
ImageSize -> 250], {f, {w[\[Theta]], w2[\[Theta]]}}]

--
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/

```

• Prev by Date: Re: a problem about NDSolve and NIntegrate
• Next by Date: Re: Reading Coordinates from Plot
• Previous by thread: Re: Exporting to a 3D file...
• Next by thread: Re: Drawing Potatoes and a Problem with Piecewise