# How use Locator for planar point and image of that point under a function?

Consider the following function as mapping the {x,y}-plane to a copy of that plane:

F[{x_, y_}] := {x^2 - y^2, 2 x y}


I want to visualize what that mapping does to a particular point against a background of a rectangular grid in the domain and the image point under F of that grid in the image plane.

Making a static visualization for a particular point is straightforward:

With[{pt = {1, 1}},
domStatic = Show[{
ParametricPlot[{x, y}, {x, -2, 2}, {y, -2, 2},
Mesh -> {5, 5}, PlotStyle -> Opacity[0.1, Lighter@Yellow]],
Graphics[{PointSize@Large, Red, Point[pt]}]},
Frame -> False, ImageSize -> Scaled[0.3]];
imageStatic = Show[{
ParametricPlot[F[{x, y}], {x, -2, 2}, {y, -2, 2},
Mesh -> {5, 5}, PlotStyle -> Opacity[0.1, Lighter@Yellow]],
Graphics[{PointSize@Large, Red, Point[F[pt]]}]},
Frame -> False, ImageSize -> Scaled[0.3]];
Row[{domStatic, Spacer[10], imageStatic}]
]


Now I want to make the domain point pt dynamic and have the image F[pt] under F of that point move accordingly as the pt is moved.

This is easy using a 2D-slider. First make the domain and image graphics depend on the point as an argument...

Clear[pt, dom, image]
dom[pt_] := Show[{
ParametricPlot[{x, y}, {x, -2, 2}, {y, -2, 2},
Mesh -> {5, 5}, PlotStyle -> Opacity[0.1, Lighter@Yellow]],
Graphics[{PointSize@Large, Red, Point[pt]}]},
Frame -> False, ImageSize -> Scaled[0.3]];
image[pt_] := Show[{
ParametricPlot[F[{x, y}], {x, -2, 2}, {y, -2, 2},
Mesh -> {5, 5}, PlotStyle -> Opacity[0.1, Lighter@Yellow]],
Graphics[{PointSize@Large, Red, Point[F[pt]]}]},
Frame -> False, ImageSize -> Scaled[0.3]];


... and then use Manipulate:

Manipulate[
Row[{dom[pt], Spacer[10], image[pt]}],
{{pt, {1, 1}}, {-2, -2}, {2, 2}}
]


Question: How can I produce such a dynamic visualization but by using a Locator for the point in the domain (instead of a 2D-slider)?

The following does not work: it puts the Locator in the image plane instead of in the domain plane!

What's wrong and how can it be fixed?

Manipulate[
Row[{dom[pt], Spacer[10], image[pt]}],
{{pt, {1, 1}}, Locator}
]


F[{x_, y_}] := {x^2 - y^2, 2 x y}


Let's generate static background images:

backgroundDomain =
ParametricPlot[{x, y}, {x, -2, 2}, {y, -2, 2},
Mesh -> {5, 5},
PlotStyle -> Opacity[0.1, Lighter@Yellow],
Frame -> False,
ImageSize -> 300];
backgroundImage =
ParametricPlot[F[{x, y}], {x, -2, 2}, {y, -2, 2},
Mesh -> {5, 5},
PlotStyle -> Opacity[0.1, Lighter@Yellow], Frame -> False,
ImageSize -> 300];


Now let's create a display:

Row[
{LocatorPane[Dynamic[pt], backgroundDomain],
Dynamic[Show[{backgroundImage, Graphics[{Red, PointSize[Large], Point[F[pt]]}]}]]}]


Is that what you're after? Might want to parameterize the background images, with size for example.

Edit

You can change the appearance of the Locator with the Appearance option. For example,

LocatorPane[
Dynamic[pt],
backgroundDomain,
Appearance -> Graphics[{Red, Disk[]}, ImageSize -> 10]]

• That does display what I want, but I was hoping there was a way to do it in a Manipulate (where the backgrounds could be set inside an Initialization. Commented Aug 19, 2022 at 0:22

We use pts = RegionNearest[Rectangle[{-2, -2}, {2, 2}]]@pts; to limit the point to the Rectangle[{-2, -2}, {2, 2}].

F[{x_, y_}] = {x^2 - y^2, 2 x y};
Manipulate[
Row[{
ParametricPlot[{x, y}, {x, -2, 2}, {y, -2, 2}, Mesh -> {5, 5},
PlotStyle -> Opacity[0.1, Lighter@Yellow], Frame -> False,
ImageSize -> Medium],
ParametricPlot[F@{x, y}, {x, -2, 2}, {y, -2, 2}, Mesh -> {5, 5},
PlotStyle -> Opacity[0.1, Lighter@Yellow],
Epilog -> {PointSize@Large, Red, Point[Dynamic@F@pt]},
Frame -> False, ImageSize -> Medium,
PerformanceGoal -> "Quality"]
}],
{{pt, {0, 0}}, Locator, TrackingFunction ->
Function[pos, pt = RegionNearest[Rectangle[{-2, -2}, {2, 2}]]@pos],
Appearance -> Graphics[{Red, AbsolutePointSize[10], Point[{0, 0}]}]
}
]


• I've made your code work more smoothly, hope you don't mind, you can update the gif if you want.
– Kuba
Commented Aug 19, 2022 at 10:54
• @Kuba Thank you very much, I learn more from the new edition. I will updated the gif later. Commented Aug 19, 2022 at 10:58
• @cvgmt: this does not seem to work if I change ImageSize -> Medium to ImageSize -> Scaled[0.4], say. Then the locator appears inside the right-haind oval! Commented Aug 19, 2022 at 15:28
• @cvgmt: How did you produce for your answer an animated gif from the Manipulate? Commented Aug 22, 2022 at 19:11
• @murray I am using ScreenToGif screentogif.com Commented Aug 22, 2022 at 22:49