Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg119512] Re: Curve Tracking and fetching Locator coordinates
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Tue, 7 Jun 2011 06:48:01 -0400 (EDT)

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


  • Prev by Date: implicit surfaces from older version of Mathematica
  • Next by Date: Re: How show axes labels with AxesOrigin->{0,0,0} in 3D?
  • Previous by thread: Re: Curve Tracking and fetching Locator coordinates
  • Next by thread: Re: Curve Tracking and fetching Locator coordinates