Re: Slow plotting of reflected parametric "butterflies"

*To*: mathgroup at smc.vnet.net*Subject*: [mg124537] Re: Slow plotting of reflected parametric "butterflies"*From*: Chris Young <cy56 at comcast.net>*Date*: Mon, 23 Jan 2012 02:58:23 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*References*: <jf8ql4$3pl$1@smc.vnet.net> <jfgva3$ph4$1@smc.vnet.net>

On 2012-01-22 12:26:43 +0000, Bill Rowe said: > On 1/21/12 at 5:20 AM, cy56 at comcast.net (Chris Young) wrote: > >> I'm thinking that it's much safer programming style to always >> isolate any functions using Set (rather than SetDelayed) inside a >> module; otherwise aren't there "exposed" global variables? If these >> get assigned some value, wouldn't the function be broken? > > I don't agree using Set is any safer/riskier than SetDelayed. > But I do agree it is important to understand the difference > between them and when each is appropriate. > > Localizing variables inside Module clearly isolates them from > the external environment. But Module localizes variables by > creating new variables which can cause unexpected difficulties. > > That is: > > In[1]:= a = 2; > {Module[{a = 4}, {Names["a*"], 4}], a} > > Out[2]= {{{a,a$2093},4},2} > > Contrast that with > > In[1]:= a = 2; > {Block[{a = 4}, {Names["a*"], 4}], a} > > Out[2]= {{{a},4},2} But I can't use Block for my purposes. I can't define the MSeg function. All I get is the lines at the top and bottom. So I'm hoping that using Module where Block is below is OK. The other solution would seem to be to Clear any variables in a Set function. So you'd want to make sure you didn't need them. Manipulate[ Block[ { \[ScriptCapitalA] = {Ax, Ay, Az}, \[ScriptCapitalB] = {Bx, By, Bz}, \[ScriptCapitalC] = {Cx, Cy, Cz}, \[ScriptCapitalD] = {Dx, Dy, Dz}, \[ScriptCapitalP], \[ScriptCapitalQ], n, k, t }, (* points riding along the "rails" \[ScriptCapitalA]\ \[ScriptCapitalC] and \[ScriptCapitalB]\[ScriptCapitalD]: *) \ \[ScriptCapitalP][n_] = (1 - n) \[ScriptCapitalA] + n \[ScriptCapitalC]; \[ScriptCapitalQ][n_] = (1 - n) \[ScriptCapitalB] + n \[ScriptCapitalD]; \[HorizontalLine]MSeg[\[ScriptCapitalA]_, \[ScriptCapitalB]_, k_, t_] = (\[ScriptCapitalA] + \[ScriptCapitalB])/2 + k (t - 1/2) (\[ScriptCapitalB] - \[ScriptCapitalA]); (* reflections of the "butterfly" across all the coordinate planes *) Show[ ParametricPlot3D[ Table[ ( { {\[ScriptI], 0, 0}, {0, \[ScriptJ], 0}, {0, 0, \[ScriptK]} } ). \[HorizontalLine]MSeg[\[ScriptCapitalP][ u], \[ScriptCapitalQ][u], 2 u - 1, v], {\[ScriptI], {-1, 1}}, {\[ScriptJ], {-1, 1}}, {\[ScriptK], {-1, 1}} ], {u, 0, 1}, {v, 0, 1}, PlotPoints -> plotPts, Mesh -> mesh, MeshStyle -> Tube[tubeR], MeshFunctions -> {{x, y, z, u, v} \[Function] v}, MeshShading -> {Lighter[Blue, .5], Yellow, Orange, Yellow, Lighter[Blue, .5]}, BoundaryStyle -> Tube[tubeR], MaxRecursion -> maxRecurs ], (* the corners of the twisted sheet *) With[{pts = {\[ScriptCapitalA], \[ScriptCapitalB], \ \[ScriptCapitalC], \[ScriptCapitalD]}}, Graphics3D[ {Table[{Hue[(k - 1)/4], Sphere[pts[[k]], ptRad]}, {k, 1, 4}], Gray, Sphere[Plus @@ pts/4, ptRad]}] ], Lighting -> "Neutral", PlotRange -> 4, Axes -> True, AxesLabel -> {"x", "y", "z"} ] ], {{Ax, 0}, -4, 4, .125}, {{Ay, -4}, -4, 4, .125}, {{Az, -4}, -4, 4, .125}, {{Bx, -4}, -4, 4, .125}, {{By, 0}, -4, 4, .125}, {{Bz, -4}, -4, 4, .125}, {{Cx, 0}, -4, 4, .125}, {{Cy, 0}, -4, 4, .125}, {{Cz, -2}, -4, 4, .125}, {{Dx, -4}, -4, 4, .125}, {{Dy, -4}, -4, 4, .125}, {{Dz, 0}, -4, 4, .125}, {{mesh, 4}, 0, 9}, {{tubeR, 0.03}, 0, 0.1, 0.01}, {{plotPts, 6}, 2, 30, 1}, {{maxRecurs, 1}, 0, 4, 1}, {{ptRad, .1}, 0, 0.5, 0.01}, {{tubeR, .03}, 0, 0.5, 0.01} ]