[Date Index]
[Thread Index]
[Author Index]
Re: Curve Tracking and fetching Locator coordinates
*To*: mathgroup at smc.vnet.net
*Subject*: [mg119458] Re: Curve Tracking and fetching Locator coordinates
*From*: Heike Gramberg <heike.gramberg at gmail.com>
*Date*: Sun, 5 Jun 2011 07:01:37 -0400 (EDT)
I'm by no means an expert in Dynamics myself, but as far as I understand it
if you specify something like Locator[Dynamic[pt, f]], then when the locator is moved,
f[val,pt] is evaluated where val is the current location of the mouse pointer and pt the
current position of the Locator. The Locater is then moved to the updated value of pt.
So if you want to move the Locator along the graph y=Sin[x] for example, you could do
something like
DynamicModule[{pt = {0, 0}},
Show[Plot[Sin[x], {x, 0, 2 Pi}],
Graphics[Locator[Dynamic[pt, (pt = {#[[1]], Sin[#[[1]]]}) &]]],
ImageSize -> 400]]
See the "More Information" tab in the documentation of Dynamic for a more detailed
explanation.
To use the position of the Locator in a calculation you can simply use Dynamic[func[pt]], e.g.:
DynamicModule[{pt = {1, 0}},
Row[{Graphics[{Circle[],
Locator[Dynamic[pt, (pt = Normalize[#]) &]]}, PlotRange -> 2,
ImageSize -> 400], Dynamic[pt^2]}]]
Heike
On 4 Jun 2011, at 11:19, Just A Stranger wrote:
> 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 :)
Prev by Date:
**Re: ContourPlot ColorFunction Question**
Next by Date:
**Mapping points**
Previous by thread:
**Re: Curve Tracking and fetching Locator coordinates**
Next by thread:
**Re: Curve Tracking and fetching Locator coordinates**
| |