Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)$.

share|improve this question
up vote 4 down vote accepted

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

share|improve this answer
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. – QuadraticU May 21 '13 at 16:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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