Say I have some Graphics3D object that I'm looking at from a top down perspective, e.g.:

Graphics3D[{Sphere[{-1, 3, 0}, 1], Sphere[{0, 1, 0}]}, ViewPoint -> Top]

How might I use Manipulate[] so that I can click somewhere on this image and generate an ${x,y}$ output corresponding to the position of the mouse on a projection plane parallel to my screen with respect to the coordinate system in the image? In the above example, for instance, clicking on the center of first sphere would output $(-1, 3)$, while clicking on the center of the latter would output $(0,1)$.


1 Answer 1


I am not sure I understand completely what you desire to do - especially the following is not quite clear: when you click on a sphere, how would Manipulate know the depth of the desired point? (due to perspective, this will affect the output)

Then again, Mathematica offers a way to return coordinates with respect to "front and back intercepts with the 3D bounding box", see MousePosition documentation, namely "Graphics3DBoxIntercepts".

To illustrate, let's create an example:

  {Red, PointSize[Large], Point[coord[[1]]]},
  {Green, PointSize[Large], Point[coord[[2]]]},
  {Blue, Line[coord]},
  {Directive[Yellow, Opacity[0.5]], 
   Sphere[{-1, 3, 0}, 1]}, {Directive[Orange, Opacity[0.5]], 
   Sphere[{0, 1, 0}]}},
 ViewPoint -> view, Axes -> axes, AxesLabel -> {"x", "y", "z"}, 
 ImageSize -> 
  Medium], {"MouseClicked" :> (coord = 
Grid[Transpose@{{"Front", "Back"}, coord}]}], {view, {Top, Left, 
Right, Front, Bottom}, 
ControlType -> SetterBar}, {axes, {False, True}},
Initialization :> {coord = {{0, 0, 0}, {0, 0, 0}}}]

You can see that I use MousePosition on the discussed object "Graphics3DBoxIntercepts" to get the coordinates (plus an EventHandler to capture the click). The red point will then mark the point with respect to the "front intercept", the green on the back, and you can use Manipulate to look at other viewpoints.

I hope this helps... (to get you started)

enter image description here

  • $\begingroup$ I like this answer quite a bit. Regarding not knowing the depth of an object, and how this depends on perspective, this is why I was mentioning {x,y} coordinates on a perspective-based projective plane (i.e. my screen) instead of {x,y,z} coordinates associated with the actual object. $\endgroup$
    – QuadraticU
    Commented May 21, 2013 at 16:10

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.