MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Locator + EventHandler

  • To: mathgroup at
  • Subject: [mg128357] Re: Locator + EventHandler
  • From: Alexei Boulbitch <Alexei.Boulbitch at>
  • Date: Tue, 9 Oct 2012 00:39:27 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:

Albert, Alexander and Miranda,

Thank you very much for the answers. The option LocatorAutoCreate -> True solves the problem.

Miranda, your solution is not exactly what I have in mind, since locators in it are not attached to the interpolate function. Therefore, I cannot adjust the points with it. However, using EventHandler in this construct might be interesting, since it may give an additional flexibility.

A next question I would like to know the answer is how in this or analogous problem to implement two (or in general, several) families of locators. Different families should have different appearances and operate with different lists of points.

Thank you once more.

With your help I have written a function to digitalize a curve from an image. I post it here to be used by everybody who needs it, and eventually, to improve it :).

copyCurve[image_, size_Integer, x1_, x2_, y1_, y2_] :=
  DynamicModule[{im, pts = {},
    loc = Graphics[{{Blue, Thin, Circle[{0, 0}, 0.5]}},
      ImageSize -> 10], X1, X2, Y1,
    Y2, \[CapitalDelta]X, \[CapitalDelta]Y, g, myRound},
   im = ReplacePart[image, {4, 2} -> size];
   myRound[x_] := Round[1000.*x]/1000. // N;
      Dynamic@Show[{im, Graphics[{Blue, Opacity[0.5], Line[pts]}]
             }], LocatorAutoCreate -> True, Appearance -> loc
     (* Begin the buttons row *)
       (* Begin button "Memorize scale X" *)
       Button["Memorize scale X",
        X1 = Min[Transpose[myRound /@ pts][[1]]];
        X2 = Max[Transpose[myRound /@ pts][[1]]];
        \[CapitalDelta]X = X2 - X1;
        ],(* End of button "Memorize scale X" *)
       (* Begin button "Memorize scale Y" *)
       Button["Memorize scale Y",
        Y1 = Min[Transpose[myRound /@ pts][[2]]];
        Y2 = Max[Transpose[myRound /@ pts][[2]]];
        \[CapitalDelta]Y = Y2 - Y1;
        ],(* End of button "Memorize scale Y" *)
       }],(* End the buttons row *)
     (* Begin button "Make the list of the curve's points" *)
     Button[Style["Make the list of the curve's points" , Bold],
      g[{a_, b_}] := {(x1*X2 - x2*X1)/\[CapitalDelta]X +
         a/\[CapitalDelta]X*Abs[x2 - x1], (
         y1*Y2 - y2*Y1)/\[CapitalDelta]Y +
         b/\[CapitalDelta]Y*Abs[y2 - y1]};
      listOfPoints = Map[myRound, Map[g, pts]]
                  ](* End of button "Make the list..." *)
     }, Alignment -> Center]


The function copyCurve takes the coordinates of curve points from an image and memorises them in a list entitled "listOfPoints"

image is any image. It should have Head=Image, but may be also a Graphics object, since no specific functions of image have been used.

size is the integer number giving the size that the image appearing after execution of the function will have. It should be chosen to make the curve best visible.

x1 and x2 are the reference coordinates along x , while
y1 and y2 are the reference coordinates along y. They are chosen typically on the coordinate axes seen on the image. The choice of them on the axes is, however, not necessary. Any pair of points is suitable, if their coordinates are known.

Step 1: One should execute the function

Step 2: Alt+Click on the point with x-coordinate x1. This brings up the first locator visible as a blue circle. Alt+Click on that with x2 which gives rise to the second locator. Adjust the locators, if necessary. Press the button "Memorize scale X".

Step 3: Move the locators to the points with the coordinates y1 and y2. Press the button "Memorize scale Y". Now the both scales are captured.

Step 4: Move the locators to the first two points of the curve to be captured. Successively Alt+Click on the other curve points. Each Alt+Click will generate an additional locator. Adjust locators, if necessary. To remove one make Alt+Click on the unnecessary locator.

Step 5: Press the button "Make the list...". This assigns the captured list to the variable "listOfPoints". Done.

The "listOfPoints" is a global variable. It can be addressed everywhere in the notebook.

Best, Alexei

Alexei BOULBITCH, Dr., habil.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch at

  • Prev by Date: Re: Markers in list plot
  • Next by Date: Re: fast summing alternative?
  • Previous by thread: Re: Locator + EventHandler
  • Next by thread: pattern matching