# TrackingFunction in Manipulate

I use this Manipulate to generate a dynamic graphic:

Manipulate[pntx2=First[pt2]; pnty2=Last[pt2];
Graphics[{{Red, Circle[]},
{Thick, Line[{{0, 0}, pt2}]},
{Point[{{0,pnty2}}]},
{Dashed, Line[{{0,pnty2}, pt2},VertexColors->{Black, Black}]},
{Thickness[0.015], Line[{{0,0},{0,pnty2}},VertexColors->{Cyan, Cyan}]}},
Axes -> True, PlotRange -> 3/2],
{{pt2, {1, 1}/Sqrt[2]}, Locator, TrackingFunction ->((pt2 = Normalize[#]) &)}]


Can someone explain me what does ((pt2 = Normalize[#]) &) exactly mean?

• To expand further, it's a question of precedence: (pt2 = Normalize[#] &) is equivalent to (pt2 = (Normalize[#] &)). This would set pt2 to the function Normalize[#] & (just once, when the TrackingFunction option was evaluated). Since the value of var = rhs is rhs, the option would be effectively the same as TrackingFunction -> (Normalize[#] &), which would disable the movement of the Locator, since it does not update pt2 whenever the Locator is moved. Jun 6, 2017 at 22:54

pt2 is the point where your mouse tries to drag the traker (the small black cross & circle).

((pt2 = Normalize[#]) &) means that before being updated, the vector representing the point where you tried to drag the traker is normalized. This way the tracker remains on the red ring, for it was deffined having raius 1 by default.

If you deffined the ring with radius 2 you would need to change this line to ((pt2 = 2 Normalize[#]) &).

Also it would be good to update the starting position: {pt2, 2 {1, 1}/Sqrt[2]}

A complete example:

Manipulate[pntx2 = First[pt2]; pnty2 = Last[pt2];
Graphics[{{Red, Circle[{0, 0}, 2]}, {Thick,
Line[{{0, 0}, pt2}]}, {Point[{{0, pnty2}}]}, {Dashed,
Line[{{0, pnty2}, pt2},
VertexColors -> {Black, Black}]}, {Thickness[0.015],
Line[{{0, 0}, {0, pnty2}}, VertexColors -> {Cyan, Cyan}]}},
Axes -> True, PlotRange -> 5/2], {{pt2, 2 {1, 1}/Sqrt[2]}, Locator,
TrackingFunction -> ((pt2 = 2 Normalize[#]) &)}]

• @Kuba, sorry man, I rolled back your edit for we both edited at the same time...
– ivbc
Jun 6, 2017 at 20:42