2
$\begingroup$

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

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

 Manipulate[
  Show[
   cameraImage
   ,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?

$\endgroup$
  • $\begingroup$ Damn! You got me :D $\endgroup$ – Fraccalo Aug 9 '18 at 20:19
3
$\begingroup$

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

Manipulate[
 LocatorPane[
  Dynamic[pts, With[{update = #[[1]] - pts[[1]]},
     If[Max@Abs[update] == 0, pts = #, pts += {update, update}]] &],
  Dynamic@Show[
    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}]
$\endgroup$
  • $\begingroup$ Thanks a lot, exactly what I was looking for! $\endgroup$ – Fraccalo Aug 9 '18 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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