3
$\begingroup$

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}]
]

Static picture of mapping F

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}}
]

Dynamic picture of F with 2D-slider

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}
 ]

Error: dynamic picture of F with Locator

$\endgroup$

2 Answers 2

5
$\begingroup$

Here's your F:

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]]
$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – murray
    Commented Aug 19, 2022 at 0:22
5
$\begingroup$

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}]}]
   }
]

enter image description here

$\endgroup$
6
  • $\begingroup$ I've made your code work more smoothly, hope you don't mind, you can update the gif if you want. $\endgroup$
    – Kuba
    Commented Aug 19, 2022 at 10:54
  • $\begingroup$ @Kuba Thank you very much, I learn more from the new edition. I will updated the gif later. $\endgroup$
    – cvgmt
    Commented Aug 19, 2022 at 10:58
  • $\begingroup$ @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! $\endgroup$
    – murray
    Commented Aug 19, 2022 at 15:28
  • $\begingroup$ @cvgmt: How did you produce for your answer an animated gif from the Manipulate? $\endgroup$
    – murray
    Commented Aug 22, 2022 at 19:11
  • $\begingroup$ @murray I am using ScreenToGif screentogif.com $\endgroup$
    – cvgmt
    Commented Aug 22, 2022 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.