MathGroup Archive 2011

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

Search the Archive

Re: Curve Tracking and fetching Locator coordinates

  • To: mathgroup at
  • Subject: [mg119490] Re: Curve Tracking and fetching Locator coordinates
  • From: "Alexei Boulbitch" <boulbitch at>
  • Date: Mon, 6 Jun 2011 06:24:31 -0400 (EDT)

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 *)
(* 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

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

Dr. , habil. 
Department for Material Development
ZAE Weiergewan
11, rue Edmond Reuter
L-5326 Contern, Luxembourg

Tel.          ++352-2454-2566
Fax.:        ++352 424737201
mobile:       +49 (0) 151 524 066 44  
E-mail:      alexei.boulbitch at 
                boulbitch at

Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro!

  • Prev by Date: Re: Question about function construction
  • Next by Date: Re: Mapping points
  • Previous by thread: Re: Curve Tracking and fetching Locator coordinates
  • Next by thread: Re: Curve Tracking and fetching Locator coordinates