Re: Drawing Potatoes and a Problem with Piecewise
- To: mathgroup at smc.vnet.net
- Subject: [mg80190] Re: [mg80121] Drawing Potatoes and a Problem with Piecewise
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Tue, 14 Aug 2007 07:11:43 -0400 (EDT)
- Organization: Mathematics & Statistics, Univ. of Mass./Amherst
- References: <200708130830.EAA27361@smc.vnet.net>
- Reply-to: murray at math.umass.edu
Rotating the first potato, w, makes quite obvious that it's in 4 pieces: you can see the slits of light between the pieces! 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? > > 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]]}}] > > > -- Murray Eisenberg murray at math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305
- References:
- Drawing Potatoes and a Problem with Piecewise
- From: "David Park" <djmpark@comcast.net>
- Drawing Potatoes and a Problem with Piecewise