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


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

Re: Can't use Table with Dynamic variables?

Started by"E. Martin-Serrano" <eMartinSerrano@telefonica.net>
First post2011-05-09 11:38 +0000
Last post2011-05-10 12:53 +0000
Articles 2 — 2 participants

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


Contents

  Re: Can't use Table with Dynamic variables? "E. Martin-Serrano" <eMartinSerrano@telefonica.net> - 2011-05-09 11:38 +0000
    Re: Can't use Table with Dynamic variables? "Christopher O. Young" <cy56@comcast.net> - 2011-05-10 12:53 +0000

#2239 — Re: Can't use Table with Dynamic variables?

From"E. Martin-Serrano" <eMartinSerrano@telefonica.net>
Date2011-05-09 11:38 +0000
SubjectRe: Can't use Table with Dynamic variables?
Message-ID<iq8jnc$72i$1@smc.vnet.net>
Try applying the Dynamic[] wrapper to each element in the table (inside the
table construct not outside). I experienced the same problem in several
occasions and solved  it in this form. Anyway the movement of the dragged
objects is sluggish, just in the border of which could be considered as
acceptable despite that just four or the five locators in the involved
construct does not seem to be a heavy demand.


-----Mensaje original-----
De: Christopher O. Young [mailto:cy56@comcast.net] 
Enviado el: lunes, 09 de mayo de 2011 12:18
Para: mathgroup@smc.vnet.net
Asunto:  Can't use Table with Dynamic variables?

By following the advice in the helpful free PDF tutorial
"DynamicInteractivity", I used With to pull out the iterator for the Table
from the enclosing Dynamic expression.

Finally got the 3D points moving around under the control of the 2D locators
and the height sliders. I have the Bezier curves, but I can't get the
interpolating curve to work with Graphics and Dynamic yet.

Also, if you're not careful, when you try to drag a locator, the whole 2D
graphing pane gets dragged around instead.  What's causing this?


P = {{1, 0}, {1, 1}, {2, 2}, {3, 3}}

GraphicsGrid[
 {
  {
   "Z-coordinate",
   "Radius"
   },
  {
   Slider[Dynamic[h], {-2, 2, 0.25}, Appearance -> "Labeled"],
   Slider[Dynamic[r], {0, 1, 0.01}, Appearance -> "Labeled"]
   },
  {
   Graphics[
    {
     Dynamic[
      Table[
       With[{k = k},
        Locator[Dynamic[P[[k]]]]
        ],
       {k, 1, 4}
       ]
      ],
     
     Dynamic[
      BezierCurve[{P[[1]], P[[2]], P[[3]], P[[4]]}]
      ]
     },
    PlotRange -> 5,
    Frame -> True,
    Axes -> True
    ],
   
   Dynamic[
    Graphics3D[
     {
      Table[
       Sphere[{P[[k, 1]], P[[k, 2]], h}, r],
       {k, 1, 4}
       ],
      
      Tube[
       BezierCurve[
        {{P[[1, 1]], P[[1, 2]], h}, {P[[2, 1]], P[[2, 2]],
          h}, {P[[3, 1]], P[[3, 2]], h}, {P[[4, 1]], P[[4, 2]], h}}]
       ]
      },
     PlotRange -> 5,
     Axes -> True,
     ViewPoint -> {10, 5, 8},
     ViewVertical -> {0, 1, 0},
     AxesLabel -> {"x", "y", "z"}
     ]
    ]
   }
  },
 ItemAspectRatio -> {0.025, 0.04, 1},
 Dividers -> {All, {True, False, True, True}},  Spacings -> {25, 20}  ]





Dynamic[
 Plot[
  Interpolation[{P[[1]], P[[2]], P[[3]], P[[4]]}][x],
  {x, P[[1, 1]], P[[4, 1]]}
  ]
 ]


[toc] | [next] | [standalone]


#2274

From"Christopher O. Young" <cy56@comcast.net>
Date2011-05-10 12:53 +0000
Message-ID<iqbcfu$k2o$1@smc.vnet.net>
In reply to#2239
On 5/9/11 7:38 AM, in article iq8jnc$72i$1@smc.vnet.net, "E. Martin-Serrano"
<eMartinSerrano@telefonica.net> wrote:

> Try applying the Dynamic[] wrapper to each element in the table (inside the
> table construct not outside). I experienced the same problem in several
> occasions and solved  it in this form. Anyway the movement of the dragged
> objects is sluggish, just in the border of which could be considered as
> acceptable despite that just four or the five locators in the involved
> construct does not seem to be a heavy demand.

After hours of work, I finally got a pretty fast version of the 2D vs. 3D
curve-plotter.

The only trouble now is that I can't seem to have both the function
definition f[x] at the top and also have DynamicModule save my point
variables. They get reset each time the graph is plotted.


DynamicModule[
 {
  P = {{-4, 0}, {2, 1}, {3, 2}, {4, 3}},
  f
  },

 f[x_] := InterpolatingPolynomial[Table[P[[k]], {k, 1, Length[P]}], x];

 GraphicsGrid[
  {
   {"Z-coordinate",
    "Radius"},
   {Slider[Dynamic[h], {5, -5, -1}, Appearance -> "Labeled"],
    Slider[Dynamic[r], {0, 1, 0.01}, Appearance -> "Labeled"]},
   {
    Dynamic[
     Deploy[    (*
      Use Deploy to eliminate accidental movements of the graphics \
frame. *)
      Show[
       Graphics[
        {
         Table[
          With[{k = k}, Locator[Dynamic[P[[k]]]]], {k, 1, Length[P]}
          ],
         (*
         Plot the B=E9zier curve with these points as its control \
points, and also the accompanying "control polygon": *)
        
         BezierCurve[Table[P[[k]], {k, 1, Length[P]}]],
         {Thick, Dotted, Line[Table[P[[k]], {k, 1, Length[P]}]]}
         }
        ],  (* Graphics *)
      
       (*
       Plot the interpolation curve from the point furthest to the \
left to the point furthest to the right: *)
      
       Plot[f[x], {x, -5, 5}],
      
       PlotRange -> 5,
       Frame -> None,
       Axes -> True
       ]     (* Show *)
      ]     (* Deploy *)
     ], (*
    Dynamic *)
   
    Dynamic[
     Show[
      Graphics3D[
       {
        Table[Sphere[{P[[k, 1]], P[[k, 2]], h}, r], {k, 1, Length[P]}],
        Tube[
         BezierCurve[
          Table[{P[[k, 1]], P[[k, 2]], h}, {k, 1, Length[P]}]]],
        {Thick, Dotted,
         Line[Table[{P[[k, 1]], P[[k, 2]], h}, {k, 1, Length[P]}]]}
        },
       PlotRange -> 5,
       Axes -> True,
       AxesLabel -> {"x", "y", "z"}
       ],  (* Graphics3D *)
     
      ParametricPlot3D[{t, f[t], h}, {t, -5, 5}] /.
      
       Line[pts_, rest___] :> Tube[pts, 0.1, rest]
      ]   (* Show *)
     ] (* Dynamic *)
    }
   },
  Frame -> None,
  ItemAspectRatio -> {0.1, 0.1, 1},
  Dividers -> {All, {True, False, True, True}},
  Spacings -> {50, 20}
  ]  (* GraphicsGrid *)
 ](* DynamicModule *)

[toc] | [prev] | [standalone]


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


csiph-web