MathGroup Archive 2011

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

Search the Archive

Re: Curve Tracking and fetching Locator coordinates

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119541] Re: Curve Tracking and fetching Locator coordinates
  • From: Alexei Boulbitch <alexei.boulbitch at iee.lu>
  • Date: Wed, 8 Jun 2011 07:15:20 -0400 (EDT)

You are right, Murray, so get I. I should admit that I do not understand, how to get rid of it. I have a further problem here.
I do not see how to force the function alongTheCurve to understand an arbitrary function f that is different from Sin[x] or
Cos[x] or alike. Say, such as a combination of seceral elementary functions as Sin{x]*Exp[-x].

Of coarse, all problems (except for messages) are removed at once, if the function Sin{x]*Exp[-x] is typed-in manually.
For example, check this:


alongTheCurve2[xMin_, xMax_] :=
   DynamicModule[{pt = {xMin, Sin[xMin]*Exp[-xMin]}},

(*The Plot and the Locator are combined by Show*)

    Show[{(*Here is the plot of your curve*)
      Plot[Sin[x] Exp[-x], {x, xMin,
        xMax},
(*This is the inset into the plot showing the locator \
value*)
Epilog ->
        Inset[Style[Dynamic[{pt[[1]], Sin[pt[[1]]]*Exp[-pt[[1]]]}],
          Red, 14], Scaled[{0.8, 0.8}]]],

      (*This part draws the locator*)

      Graphics[ Locator[Dynamic[{pt[[1]], Sin[pt[[1]]]*Exp[-pt[[1]]]}
                                                                       \
         ]
                                                             ]
                                         ]
            }]
                           ];

alongTheCurve2[0, 2 \[Pi]]


But typing this in each time is too boring. The messages here state that the tag Times in Dynamic[{pt[[1]], Sin[pt[[1]]]*Exp[-pt[[1]]]}]
is protected.

Alexei





With that code and, say, the example alongTheCurve[Sin, 0, 2 \[Pi]], as
I move the locator, I get a huge list of messages generated, all of the
form "Set::write : Tag Sin in Sin[xxxxx] is Protected."

On 6/6/2011 6:24 AM, Alexei Boulbitch wrote:
>  This is straightforward. If your Locator coordinates are denoted as pt, and a function along which you want to move the Locator is f[x], then you simply need to use the construction:
>
>  Locator[Dynamic[{pt[[1]], f[pt[[1]]]
>                   }
>                  ]
>          ]
>
>  The function entitled "alongTheCurve" plots a curve f[x] from xMin to xMax and the locator slides along this curve. The value of locator can be seen in the upper right corner of the plot:
>
>  alongTheCurve[f_, xMin_, xMax_] :=
>     DynamicModule[{pt = {xMin, f[xMin]}},
>      (* The Plot and the Locator are combined by Show *)
>      Show[{
>  (* Here is the plot of your curve *)
>  Plot[f[x], {x, xMin, xMax},
>
>  (* This is the inset into the plot showing the locator value *)
>         Epilog ->
>          Inset[Style[Dynamic[{pt[[1]], f[pt[[1]]]}], Red, 14],
>           Scaled[{0.8, 0.8}]]],
>
>  (* This part draws the locator *)
>        Graphics[Locator[Dynamic[{pt[[1]], f[pt[[1]]]}]]]
>        }]
>      ];
>
>  Try this:
>  alongTheCurve[Sin, 0, 2 \[Pi]]
>  alongTheCurve[Cos, 0, 2 \[Pi]]
>
>  This function will not work in case you give it the combination of the functions like
>  alongTheCurve[Sin+Cos, 0, 2 \[Pi]]
>
>  Anyway, my aim is not to give a general solution, but only to show one possible way to answer your question.
>
>  Have fun, Alexei
>
>
>  Hello, I'm trying to figure out how to constrain a locator's movement along
>  a curve, but then fetch the coordinates of the locator to use in a
>  calculation.
>
>  The documentation has an example of a Locator moving along a circle, but
>  it's strange, because the way they do it using Normalize seems to make it
>  not clear how to access the coordinates of the locator.
>
>  This is the example code from the Locator documentation:
>
>  DynamicModule[{pt = {1, 0}},
>    Graphics[{Circle[], Locator[Dynamic[pt, (pt = Normalize[#])&]]},
>     PlotRange ->   2]]
>
>  I'm guessing the normalize function is being applied to the locator
>  position, and turning it into a unit vector (not entirely clear on how that
>  works in the code though). That has the effect of tracking the locator on a
>  unit circe But there is no variable for the locator positon. pt is simply a
>  list of constants {1,0} (although, I don't understand that entirely either,
>  because it also appears to be set to simply being a Normalize function)
>
>  Anyway, if someone could give me a hint as to what is going on in that code
>  I would much appreciate it (documentation seems sparse on the locator)
>
>  Barring that could someone just give me a quick hack for fetching the
>  locator's coordinates when it is being tracked along a circle (or better yet
>  if it is being tracked along an arbitrary curve.)?
>
>  Admittedly I have a foggy grasp about how Dynamic modules work, I'm able to
>  do basic stuff, but it starts to get unwieldy if I branch out.
>
>  Thank you for any help :)
>
>

-- 
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


-- 
Alexei Boulbitch, Dr. habil.
Senior Scientist
Material Development

IEE S.A.
ZAE Weiergewan
11, rue Edmond Reuter
L-5326 CONTERN
Luxembourg

Tel: +352 2454 2566
Fax: +352 2454 3566
Mobile: +49 (0) 151 52 40 66 44

e-mail: alexei.boulbitch at iee.lu

www.iee.lu

--

This e-mail may contain trade secrets or privileged, undisclosed or
otherwise confidential information. If you are not the intended
recipient and have received this e-mail in error, you are hereby
notified that any review, copying or distribution of it is strictly
prohibited. Please inform us immediately and destroy the original
transmittal from your system. Thank you for your co-operation.



  • Prev by Date: Re: implicit surfaces from older version of Mathematica
  • Next by Date: Re: Front end - Error when saving file
  • Previous by thread: Re: Curve Tracking and fetching Locator coordinates
  • Next by thread: Re: Curve Tracking and fetching Locator coordinates