3
$\begingroup$

I want to use the locator in MMA to reproduce the following animation:

enter image description here

But MMA's function Locator doesn't support 3D coordinates. What can I do to reproduce this animation?

$\endgroup$
1
-1
$\begingroup$

The following code is written by chyanog:

DynamicModule[{x0, y0, z0, x1, y1, z1, pts = {{0, 0, 0}, {0, 0, 1}}, 
  pos, pos1}, 
 EventHandler[
  Graphics3D[{EventHandler[
     Dynamic@{{Riffle[{Red, Green}, 
         Tooltip[Sphere[#, 0.075], #] & /@ pts]}, 
       Line[pts], {{x0, y0, z0}, {x1, y1, z1}} = pts; 
       InfinitePlane[
        pts[[1]], {{0, z0 - z1, y1 - y0}, {z0 - z1, 0, 
          x1 - x0}}]}, {"MouseDown" :> (pos = 
         Nearest[pts, MousePosition["Graphics3DBoxIntercepts"]][[1, 
           1]];
        pos1 = FirstPosition[pts, pos]), 
      "MouseDragged" :> (pts[[pos1]] = (#[[2]] + 
             Projection[
              pos - #[[2]], #[[1]] - #[[2]]]) &@(MousePosition[
            "Graphics3DBoxIntercepts"]))}]}, ImageSize -> 400, 
   PlotRange -> 
    Table[{-1, 2}, 3]], {{"MouseClicked", 
     2} :> (First@MousePosition["Graphics3DBoxIntercepts"])}]]
$\endgroup$
1
  • 4
    $\begingroup$ This code is buggy and, IMO, doesn't answer the question. Also, I think you should supply a link to the code and not to chyanog's user profile. $\endgroup$
    – m_goldberg
    Nov 25 '20 at 3:51

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.