Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8035 > unrolled thread

Re: Slow plotting of reflected parametric "butterflies"

Started byChristopher Young <cy56@comcast.net>
First post2012-01-20 06:55 +0000
Last post2012-01-21 10:25 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Slow plotting of reflected parametric "butterflies" Christopher Young <cy56@comcast.net> - 2012-01-20 06:55 +0000
    Re: Slow plotting of reflected parametric "butterflies" Chris Young <cy56@comcast.net> - 2012-01-21 10:25 +0000

#8035 — Re: Slow plotting of reflected parametric "butterflies"

FromChristopher Young <cy56@comcast.net>
Date2012-01-20 06:55 +0000
SubjectRe: Slow plotting of reflected parametric "butterflies"
Message-ID<jfb358$hr6$1@smc.vnet.net>
On Jan 19, 2012, at 11:59 AM, Murray Eisenberg wrote:

> I don't have any suggestions, at least yet, on speeding up your code. 
However, you should avoid naming things "C" and "D", since those names 
stand for objects already built into Mathematica. In fact, didn't you 
notice that running your code gives Shadowing warning messages?

I know I shouldn't name globals "C" or "D", and I try to avoid it, but 
isn't Mathematica now sophisticated enough to allow localized variables "C" and "D" as long as they don't have the same form as the functions? I.e., it 
allows "overloading" of those symbols. At any rate, I'll see if avoiding 
that speeds things up. Meanwhile, my guess is that using lists of 
functions in ParametricPlot3D is the main source of the slow-down, so 
I'm rewriting the curves as regular one-item functions.


>
> On 1/19/12 5:13 AM, Chris Young wrote:
>> I'm wondering if there's anyway I can speed this up. It's basically
>> just some sections of a parabolic hyperboloid, with the outer edges
>> curves. I'm porting it from another program, where it ran much faster.
>> I had to chop it up into parts for that program, but maybe this isn't
>> the best way to do it in Mathematica.
>>
>> http://home.comcast.net/~cy56/Mma/ReflectedButterflies.nb
>> http://home.comcast.net/~cy56/Mma/ReflectedButterfliesPic.png
>>
>> Chris Young
>> cy56@comcast.net
>>
>>
>> \[HorizontalLine]CurvedButterfly[A_, B_, C_, D_, u_,
>>   v_, \[ScriptC]_] :=
>>
>>  Table[
>>     (A + B + C + D)/4 +
>>      j Sqrt[1 - \[ScriptC] v] u/2 ((A + C)/2 - (B + D)/2) +
>>      k u/2 v (((C + D)/2 + j u (C - D)/2) - ((A + B)/2 +
>>           j u (A - B)/2)),
>>     {j, {-1, 1}}, {k, {-1, 1}}
>>     ] // FullSimplify  // Flatten[#, 1]&
>> Putting Butterfly into a Manipulate module:
>> Manipulate[
>>  With[
>>   {
>>    A = {Ax, Ay, Az},
>>    B = {Bx, By, Bz},
>>    C = {Cx, Cy, Cz},
>>    D = {Dx, Dy, Dz}
>>    },
>>   Show[
>>    ParametricPlot3D[
>>     Table[
>>      ( {
>>           {\[ScriptI], 0, 0},
>>           {0, \[ScriptJ], 0},
>>           {0, 0, \[ScriptK]}
>>          } ). #&   /@  \[HorizontalLine]CurvedButterfly[A, B, C, D, u,
>>         v, wingCurve],
>>      {\[ScriptI], {-1, 1}}, {\[ScriptJ], {-1, 1}}, {\[ScriptK], {-1,
>>        1}}],
>>     {u, 0, 1}, {v, 0, 1},
>>
>>     PlotRange ->  2.5,
>>     Lighting ->  "Neutral",
>>     ColorFunctionScaling ->  False,
>>     ColorFunction ->  ({x, y, z, u, v} \[Function]
>>        Hue[\[LeftFloor]5 v\[RightFloor]/10]),
>>     Mesh ->  None,
>>     PlotPoints ->  plotPts,
>>     AxesLabel ->  {"x", "y", "z"}
>>     ],
>>    Graphics3D[
>>     {
>>      With[{pts = {A, B, C, D}},
>>       Table[{Hue[(k - 1)/4], Sphere[pts[[k]], ptRad]}, {k, 1, 4}]
>>       ]
>>      }
>>     ]
>>    ]
>>   ],
>>  {{Ax, 1.25}, -2.5, 2.5, 0.03125},
>>  {{Ay, 2}, -2.5, 2.5, 0.03125},
>>  {{Az, 0.75}, -2.5, 2.5, 0.03125},
>>
>>  {{Bx, 1.75}, -2.5, 2.5, 0.03125},
>>  {{By, 0.5}, -2.5, 2.5, 0.03125},
>>  {{Bz, 0.125}, -2.5, 2.5, 0.03125},
>>
>>  {{Cx, 0.5}, -2.5, 2.5, 0.03125},
>>  {{Cy, 0.375}, -2.5, 2.5, 0.03125},
>>  {{Cz, 0.25}, -2.5, 2.5, 0.03125},
>>
>>  {{Dx, 0.375}, -2.5, 2.5, 0.03125},
>>  {{Dy, 0.125}, -2.5, 2.5, 0.03125},
>>  {{Dz, 1.25}, -2.5, 2.5, 0.03125},
>>
>>  {{plotPts, 4}, 2, 30, 1},
>>  {{ptRad, 0.1}, 0, 0.3},
>>  {{wingCurve, 0}, 0, 1}
>>  ]
>>
>>
>
> --
> Murray Eisenberg                     murray@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

Chris Young
cy56@comcast.net

[toc] | [next] | [standalone]


#8064

FromChris Young <cy56@comcast.net>
Date2012-01-21 10:25 +0000
Message-ID<jfe3r1$a2m$1@smc.vnet.net>
In reply to#8035
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?

Below, I put the MSeg[ ] function, which plots segment outwards from 
its midpoint, into the module used by the Manipulate.

Manipulate[
 Module[
  {
   \[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}
 ]

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web