# How to control two different variables with Locator?

It's my first time here but I didn't find answer to my problem and I can't menage that by myself,Mathematica documentation or even by previous stackexchange problems.

In Manipulate I have two variables and I want to control them separately with Locator: x coordinate of the Locator should be my, lets say, a variable, and y coordinate - b variable.

To be more precise: I want to control the position of a red point on a surface plot with the position of the Locator (probably with LocatorPane) on the contour plot. Is it possible?

potentialsurface = 1/r^12-2/r^6+1/d^12-2/d^6-(2 Exp[-(r-d)]+2 Exp[-(d-r)]-2 Exp[-(2 (r-d)-2 (d-r))*Cos[d]])
Row[{ContourPlot[potentialsurface, {r, .8, 1.6}, {d, .8, 1.6}],
Manipulate[
Show[Graphics3D[{PointSize[0.04], Red,
Point[{a, b,
1/a^12 - 2/a^6 + 1/b^12 -
2/b^6 - (2 Exp[-(a - b)] + 2 Exp[-(b - a)] -
2 Exp[-(2 (a - b) - 2 (b - a))*Cos[b]])}]},
BoxRatios -> {1, 1, 1}, Boxed -> True, Axes -> All,
ViewPoint -> {1.5, 2.4, 3}],
Plot3D[potentialsurface, {r, 0.8, 1.6}, {d, 0.8, 1.6}]],
{a,0.86, 1.6, 0.01}, {b, 0.86, 1.6, 0.01}]}] It would be great to remove sliders and replace them with the Locator on the contour plot.

is this what you mean? ClearAll[r, a, b, d];
potentialsurface =
1/r^12 - 2/r^6 + 1/d^12 -
2/d^6 - (2 Exp[-(r - d)] + 2 Exp[-(d - r)] -
2 Exp[-(2 (r - d) - 2 (d - r))*Cos[d]]);
Manipulate[
Module[{z},
z = N[1/a^12 - 2/a^6 + 1/b^12 -
2/b^6 - (2 Exp[-(a - b)] + 2 Exp[-(b - a)] -
2 Exp[-(2 (a - b) - 2 (b - a))*Cos[b]])];
Grid[{{Row[{"(", a, ",", b, ",", z, ")"}]},
{Row[{ContourPlot[potentialsurface, {r, .8, 1.6}, {d, .8, 1.6},
ImageSize -> 400],
Show[
Graphics3D[
{PointSize[0.04], Red,
Point[{a, b, z}]
},
BoxRatios -> {1, 1, 1},
Boxed -> True,
Axes -> All,
ViewPoint -> {1.5, 2.4, 3}
],
Plot3D[potentialsurface, {r, 0.8, 1.6}, {d, 0.8, 1.6},
PerformanceGoal -> "Quality"],
ImageSize -> 400
]
}
]
}}]
],
{ {a, 1.17}, Locator},
{{b, 1.16}, Locator},
TrackedSymbols :> {a, b}
]


Update:

I'm unable to rotate the potentialsurface plot because of that

This is known issue. Locator is known to prevent rotation of graphics.

If you put a LocatorPane around the ContourPlot only, then this keeps the locator active only on the ContourPlot and will not get in the way of other graphics. Now you are able to rotate the 3D graphics next to it.

But to move the locator around, need to Click the mouse on the new location, and not slide the mouse like before.

So to move the locator, simply point the mouse to the new location you want to move to instead of sliding it. Here is demo Here is the updated code

Manipulate[
Module[{z, r, d, potentialsurface, a, b},
a = pt[];
b = pt[];
potentialsurface =
1/r^12 - 2/r^6 + 1/d^12 -
2/d^6 - (2 Exp[-(r - d)] + 2 Exp[-(d - r)] -
2 Exp[-(2 (r - d) - 2 (d - r))*Cos[d]]);

z = N[1/a^12 - 2/a^6 + 1/b^12 -
2/b^6 - (2 Exp[-(a - b)] + 2 Exp[-(b - a)] -
2 Exp[-(2 (a - b) - 2 (b - a))*Cos[b]])];

Grid[{{Row[{"(", a, ",", b, ",", z, ")"}]},
{Row[{
LocatorPane[Dynamic[pt],
Graphics[
ContourPlot[potentialsurface, {r, .8, 1.6}, {d, .8, 1.6},
ImageSize -> 400]]
]
,
Show[
Graphics3D[{PointSize[0.04], Red,
Point[{pt[], pt[], z}]},
BoxRatios -> {1, 1, 1},
Boxed -> True, Axes -> All, ViewPoint -> {1.5, 2.4, 3}

],
Plot3D[potentialsurface, {r, 0.8, 1.6}, {d, 0.8, 1.6},
PerformanceGoal -> "Quality"
],
ImageSize -> 400
]
}
]
}}
]
],
{{pt, {1.17, 1.2}}, None},
TrackedSymbols :> {pt}
]

• Yes! That's exactly what's needed. Thank You very much for Your help. Now I'm go to understang what's going on in Your code :) Thanks once again! May 8 '20 at 9:00
• Oops, there is one problem: Locator works everywhere on the image. How to make him works only on a contourplot? I'm unable to rotate the potentialsurface plot because of that. Could You help me? May 8 '20 at 9:46
• @LeszekNowakowski I've updated it May 8 '20 at 10:54