I'm trying to dynamically draw an ellipse on the image acquired from a camera. See code below:

 cameraImage = CurrentImage[RasterSize -> {324, 243}];

   ,Graphics[{Red, Thick, Circle[pt, Abs[pt2 - pt]*Sqrt[2]]}]
  {{pt, {324, 243}/2.}, Locator, 
   Appearance -> 
    Style["\[CircleDot]", Red, 30]}, {{pt2, {281, 200}/2.}, Locator, 
   Appearance -> Style["\[FilledCircle]", Red, 16]}

I'd like to have the centre of the ellipse independent from the "radius" point (if I move the external point I don't change the position of the centre), while if I move the central point I'd like the ellipse to move consistently (without reshaping), i.e. the external point has to move accordingly to the movement of the centre.

I tried to adapt Kuba's code from here: Moving a locator based on the movement of another but I'm having troubles with nesting dynamic of his code with dynamic in my code.

(I also tried Dr. belisarius answer that kind-of-works but is very laggy and not reliable)

Any suggestion?

  • $\begingroup$ Damn! You got me :D $\endgroup$
    – Fraccalo
    Commented Aug 9, 2018 at 20:19

1 Answer 1


For complicated uses of Locator within Manipulate, I usually use a LocatorPane with an explicit Dynamic update function and bypass Manipulate auto-coding.

  Dynamic[pts, With[{update = #[[1]] - pts[[1]]},
     If[Max@Abs[update] == 0, pts = #, pts += {update, update}]] &],
    CurrentImage[RasterSize -> {324, 243}],
    Graphics[{Red, Thick, 
      Circle[pts[[1]], Abs[Subtract @@ pts]*Sqrt[2]]}]],
  Appearance -> {Style["\[CircleDot]", Red, 30], 
    Style["\[FilledCircle]", Red, 16]}
 {{pts, {{324, 243}/2., {281, 200}/2.}}, ControlType -> None}]
  • $\begingroup$ Thanks a lot, exactly what I was looking for! $\endgroup$
    – Fraccalo
    Commented Aug 9, 2018 at 20:20

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.