MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: 3D Graphics are too slow.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90767] Re: 3D Graphics are too slow.
  • From: m.r at inbox.ru
  • Date: Wed, 23 Jul 2008 05:59:10 -0400 (EDT)
  • References: <g61ha9$d11$1@smc.vnet.net>

On Jul 21, 3:27 am, Nayeli Espinosa <nayeli_sha... at yahoo.com.mx>
wrote:
> Hi, I have some days using Mathematica and I can't get used to the progra=
mming syntax. I can plot 3D Fractal Trees but when I increase the number of=
 iterations, my program gets to run really very slow. What can I do to opti=
mize this code for a humanly reasonable running speed?
>
> origen = {0, 0, 0}; vi = {1, 0, 0}; vj = {0, 1, 0}; vk = {0, 0, 1=
};
>
> tronco = Cylinder[{origen, vk}, 0.05];
> (*tronco={Red,Line[{origen,vk}]};*)
>
> Manipulate[
>  transf = tronco;
>  If[tr == False, k = 0, k = 0.5 ];
>  For[j = 1, j <= ite, j++,
>   transf = {transf,
>     Table[Rotate[
>       Translate[Rotate[Scale[{transf}, esc, {0, 0, 0}], phi, vi],
>        vk],  2 Pi (i - k)/br, vk], {i, 0, br - 1}]}];
>
>  Graphics3D[{tronco, transf}],
>
>  {{esc, 1, "Escalamiento (0.1 a 1) "}, 0.2,
>   1}, {{phi, Pi/2, "Angulo"}, 0, Pi},
>  {{br, 4, "Brazos"}, 2, 4, 1, RadioButton},
>  {{tr, False, "Torcimiento"}, {False, True}}, {{ite, 2,
>    "Iteraciones"}, 1, 5, 1, RadioButton}]

In your case the transformations can be carried out 'symbolically':

origen = {0, 0, 0}; vi = {1, 0, 0}; vj = {0, 1, 0}; vk = {0, 0, 1};
tronco = Cylinder[{origen, vk}, .05];

f[phi_, i_, br_, tr_, esc_, {{x1_, y1_, z1_}, {x2_, y2_, z2_}}] =
  ({{x1, y1, z1, 1}, {x2, y2, z2, 1}}.
      Transpose@ TransformationMatrix@ Composition[
         RotationTransform[2 Pi (i - k)/br, vk],
         TranslationTransform[vk],
         RotationTransform[phi, vi],
         ScalingTransform[{esc, esc, esc}, {0, 0, 0}]]
   )[[All, {1, 2, 3}]] /. k -> Boole[tr]/2;

Manipulate[
 Graphics3D[{tronco,
   Flatten@ NestList[# /. Cylinder[L_, r_] :>
        Table[Cylinder[
          f[phi, i, br, tr, esc, L], Abs[esc] r],
         {i, 0, br - 1}]&,
     tronco, ite]},
  Boxed -> False],
 {{esc, 1, "Escalamiento (0.1 a 1) "}, 0.2, 1},
 {{phi, Pi/2, "Angulo"}, 0, Pi},
 {{br, 4, "Brazos"}, 2, 4, 1, RadioButton},
 {{tr, False, "Torcimiento"}, {False, True}},
 {{ite, 2, "Iteraciones"}, 1, 5, 1, RadioButton}]

Maxim Rytin
m.r at inbox.ru


  • Prev by Date: Re: Threading over matrices
  • Next by Date: Re: how to read such kind of list?
  • Previous by thread: 3D Graphics are too slow.
  • Next by thread: a boolean algebra graph drawing question