MathGroup Archive 2007

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

Search the Archive

Re: Tracking point on a plot

  • To: mathgroup at
  • Subject: [mg76986] Re: Tracking point on a plot
  • From: David Bailey <dave at>
  • Date: Thu, 31 May 2007 03:24:33 -0400 (EDT)
  • References: <f3jgmj$d8j$>

Murray Eisenberg wrote:
> I want a locator on the plot of, say, Sin[x], that will move only
> along the graph of the function.  How should this be done?
> The closest I've come so far is the following, where the x-coordinate
> is being read from wherever the mouse is, but the corresponding
> {x,Sin[x]} point on the curve is where the locator appears:
>   DynamicModule[{p=0},
>     LocatorPane[{Dynamic[p],Dynamic[Sin[p]]},
>          Plot[Sin[x],{x,0,10}]
>        ]
>     ]
> (Also, onece the expression is evaluated, each time I move the mouse I
> get a Set::write message about Tag Sin in Sin[...] being protected.)
I think this is where the second argument to Dynamic comes in useful:


For neatness, I expect the function ff could be buried inside the 
DynamicModule, but you get the idea.

The above code just uses the X coordinate of the dragged position, but 
you could compute the nearest point on the curve if you preferred.

David Bailey

  • Prev by Date: Re: String to List
  • Next by Date: Re: String to List
  • Previous by thread: Re: Tracking point on a plot
  • Next by thread: Famous Mathematica 5.0 not working with Mathematica 6?