Message Boards Message Boards

Pseudo 3D locators: 3D controler for a 2D locator pane:

Posted 9 years ago

I've always enjoyed Mathematica's ability to create interactive figures. However, one challenge is creating 3D locators.

In an effort to create pseudo-3D locators, I designed a locator pane whose locators can be rotated in three dimensions. Said differently, the 2D plane is the projection of locators that would exist in 3D if they had a third dimension. In reality, this is only a starting point proof-of-concept, and is kind of hackey. I use the ViewPoint, ViewVertical, and ViewCenter to determine the geometric transformation needed update the locators' positions as they are moved by rotating a corresponding 3D bounding box, or independently moved within the LocatorPane (the 2D projection of the 3D space). The locators are initialized with a random third dimension. The viewpoint is not at infinity to avoid issues with the cross product, but it's close enough to mimic the desired behavior.

enter image description here

DynamicModule[{aa = 200, vp = {0, 0, 200}, vv = {0, 1, 0}, 
  pts = RandomReal[{-2, 2}, {10, 3}], pts2, zvs},
 pts2 = Transpose[{Dot[#, Cross[vv, vp/aa]] & /@ pts, Dot[#, vv] & /@ pts}];
 zvs = pts - Map[#[[1]] Cross[vv, vp/aa] + #[[2]] vv &, pts2];
 Panel@Column[{
    Row[{
      EventHandler[
       Dynamic@
        Graphics3D[{}, ImageSize -> Tiny, Boxed -> True, 
         ViewPoint -> Dynamic@vp, ViewVertical -> Dynamic@vv, 
         ViewCenter -> {1/2, 1/2, 1/2}, 
         PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}}],
       {"MouseDragged" :> (              
          pts2 = Transpose[{Dot[#, Cross[vv, vp/aa]] & /@ pts, Dot[#, vv] & /@ pts}];
          zvs = pts - Map[#[[1]] Cross[vv, vp/aa] + #[[2]] vv &, pts2])},
       PassEventsDown -> True
       ], " 3-D Slider"
      }],
    Framed@EventHandler[
      LocatorPane[Dynamic@pts2, 
       Plot[{}, {x, -2, 2}, PlotRange -> Sqrt[2] {{-2, 2}, {-2, 2}}, 
        ImageSize -> Medium, AspectRatio -> 1]],
      {"MouseDragged" :> (
         pts = zvs + Map[#[[1]] Cross[vv, vp/aa] + #[[2]] vv &, pts2];
         )},
      PassEventsDown -> True
      ]
    }]
 ]
POSTED BY: Kevin Daily
3 Replies

This is a very nice approach to indeed a challenging interface problem of 3D locators. Thanks for sharing! I added a short movie to your post. I remember another idea from Maxim Rytin Voronoi Diagram on a Sphere, but that needs to be updated for the latest version of Mathematica.

enter image description here

POSTED BY: Vitaliy Kaurov

enter image description here - you earned "Featured Contributor" badge, congratulations !

Dear @Kevin Daily, this is a great post and it has been selected for the curated Staff Picks group. Your profile is now distinguished by a "Featured Contributor" badge and displayed on the "Featured Contributor" board.

POSTED BY: EDITORIAL BOARD
POSTED BY: Pedro Fonseca
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract