MathGroup Archive 2008

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

Search the Archive

3D Picker (was: Locator 3D)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84673] 3D Picker (was: Locator 3D)
  • From: "Fred Klingener" <gigabitbucket at gmail.com>
  • Date: Wed, 9 Jan 2008 03:46:42 -0500 (EST)
  • References: <fi0ndv$5c5$1@smc.vnet.net> <fibg4o$5qo$1@smc.vnet.net> <200801070738.CAA26065@smc.vnet.net> <flv5o5$2aa$1@smc.vnet.net>
  • Reply-to: "Fred Klingener" <gigabitbucket at gmail.com>

"Murray Eisenberg" <murray at math.umass.edu> wrote in message 
news:flv5o5$2aa$1 at smc.vnet.net...
> Fred Klingener wrote:
>>> <roby.nowak at gmail.com> wrote in message 
>>> news:fi0ndv$5c5$1 at smc.vnet.net...
>>>> Hi everybody,
>>>>
>>>> is there something like a 3D Locator in Mathematica 6.0 ?
>>>> how could such a thing be realised ?
>>>>...
>> It's not Locator, but here's a cut at a way to pick 3D objects with the
>> mouse. It's based on the idea advanced by others, using the {"MouseDown" 
>> :>
>> ({f, b} = MousePosition["Graphics3DBoxIntercepts"])} return on a 3D 
>> graphic
>> inside an EventHandler.
>> ...
> Two unpleasant aspects of this (due to Mathematica 6, not your code!):
>
> (1) the cursor within the graphic persists in displaying as two curled
> arrows (suggesting rotation); but
>
> (2) there does not seem to be a way to actually rotate the 3D graphic
> while the event handler for the mouse is active.

The cursor behavior is indeed unpleasant (and it gets more unpleasant, to 
the point of unusability, and more mysterious if you wrap the example in a 
Manipulate. Maybe we'll get to that later.)

I don't know whether it helps or hurts to show the behavior using MouseMoved 
in the EventHandler rather than MouseDown:

(* 2008-01-07 Fred Klingener *)
(* 3D Picker with MouseMoved *)

(* Pluecker Line from point Q to point P use this to construct a \
Pluecker pick line through the 3D space from the front and back \
"Graphics3DBoxIntercepts" *)
pLine[P_, Q_] := {P - Q, Q\[Cross]P}

(*vector from point P normal to Pluecker line L*)
vectorLP[P_, L_] :=
 Module[{U = L[[1]], V = L[[2]]}, U\[Cross](P\[Cross]U - V)/U.U]

(*distance from point P to Pluecker line L*)
distanceLP[P_, L_] := Norm[vectorLP[P, L]];

nPoints = 10;
DynamicModule[{
  f = {0.556581, -1.43647, 1.5}
  , b = {-1.14868, 1.5, -0.792715}
  , cloud =
   Table[{RandomReal[{-1, 1}], RandomReal[{-1, 1}],
     RandomReal[{-1, 1}]}
    , {i, nPoints}]
  , d0
  , p}
 , Column[{
   Row[{EventHandler[
      image = Graphics3D[{Point[cloud]
         , Line[Dynamic@{f, b}]
         , {Red, PointSize[0.05],
          Dynamic@Point[
            p = cloud[[
              Position[
                d0 = Table[
                  distanceLP[cloud[[i]], pLine[f, b]], {i, nPoints}],
                Min@d0][[1, 1]]]]]}
         , Dynamic@Text[ToString[p], p, {0, 1.5}]
         }
        , PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}, {-1.5, 1.5}}
        , Axes -> True
        , AxesLabel -> {"x", "y", "z"}
        , AspectRatio -> Automatic
        , ImageSize -> {300, 300}
        ] (* Graphics3D *)
      , {"MouseMoved" :> ({f, b} =
          MousePosition["Graphics3DBoxIntercepts"])}
      ] (* EventHandler *)
     , Show[image, ViewPoint -> {2, 2, 2}]
     }] (* Row *)
   , Row[{Graphics[Text["Picking view.
       The pick line is normal to the screen.
       The point closest to the pick line is high-lighted.
       Click on a point to select it."], ImageSize -> {300, 60}]
     , Graphics[
      Text["Side view of point field showing point field, selected \
point and pick line.\nThe view can be manipulated with the mouse in \
the usual way"], ImageSize -> {300, 60}]
     }]
   }] (* Col *)
 ] (* DynamicModule *)

Here, we get both images mousable and EventHandler active. The selection 
snaps to the point closest to the pick line (but the pick line does not snap 
to the point). The cursor image over both views is the curly arrows, this 
time appropriate because the orientations of both images can be 
independently manipulated.

Better? Depends. But it is different, and it feeds my conviction that I 
don't have the slightest idea what's going on or how to control it.

Fred



  • References:
  • Prev by Date: 3D Picking again
  • Next by Date: Re: double clicking on a nb file starts a new instance of v 6.01
  • Previous by thread: Re: Re: Locator 3D
  • Next by thread: Re: Re: Locator 3D