Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Given a 3D image built of a combination several Graphics3D objects, is it possible to suppress rotation of the displayed image by the mouse?

To be specific, here is my custom thermometer gauge:

thermo[x_, label_String, labelSize_] := Show[{
Graphics3D[{EdgeForm[Gray], 
  FaceForm[{White, Blue, Opacity[0.05]}], 
  Cuboid[{-0.25, 0.2, -0.6}, {0.25, 0.23, 0.55}]}, 
 ViewPoint -> {0.05, -1.5, 0.}, Boxed -> False, 
 ImageSize -> {120, 300}],
Graphics3D[{Text[Style["-0.3", 12], {-0.15, 0, -0.3}], 
  Text[Style["0", 12], {-0.15, 0, 0}],
  Text[Style["3/16", 12], {0.16, 0, 3/16}] , 
  Text[Style["1/4", 12], {0.16, 0, 0.25}] , 
  Text[Style["0.3", 12], {-0.13, 0, 0.3}], 
  Text[Style[label, labelSize, Bold], {0, 0, 0.45}]}, 
 ViewPoint -> {0, -1.5, 0}, Boxed -> False, 
 ImageSize -> {120, 300}],
Graphics3D[{LightBlue, Specularity[White, 20], Opacity[0.5], 
  Sphere[{0, 0, -0.4}, 0.11]}],
Graphics3D[{Red, Specularity[White, 20], 
  Sphere[{0, 0, -0.4}, 0.1]}],
Graphics3D[{LightBlue, Opacity[0.5], 
  Tube[{{0, 0, -0.4}, {0, 0, 0.35}}, 0.05]}],
Graphics3D[{Red, Specularity[White, 20], 
  Cylinder[{{0, 0, -0.45}, {0, 0, x}}, 0.04]}],
Graphics3D[{Thickness[0.015], 
  Line[{{-0.07, 0, #}, {-0.09, 0, #}}] & /@ 
   Table[i, {i, -0.3, 0.3, 0.1}]}],
Graphics3D[{Red, Thickness[0.015], 
  Arrow[{{0.09, 0, 3/16}, {0.03, 0, 3/16}}], 
  Arrow[{{0.09, 0, 0.25}, {0.03, 0, 0.25}}]}]
}];

Try it:

thermo[x, "α", 20]

Here is how it looks:

enter image description here

Its drawback is that it can be occasionally rotated by mistake. This is not desired, of course. How cam I suppress it?

share|improve this question
    
I thank very much all participants. I like all answers. –  Alexei Boulbitch Aug 1 '13 at 8:28
add comment

6 Answers 6

up vote 10 down vote accepted

It can be tricky to position the Deploy. I found by putting it outside the Show works best:

thermo[x_, label_String, labelSize_] := 
  Deploy@Show[{Graphics3D[{EdgeForm[Gray], 
       FaceForm[{White, Blue, Opacity[0.05]}], 
       Cuboid[{-0.25, 0.2, -0.6}, {0.25, 0.23, 0.55}]}, 
      ViewPoint -> {0.05, -1.5, 0.}, Boxed -> False, 
      ImageSize -> {120, 300}], 
     Graphics3D[{Text[Style["-0.3", 12], {-0.15, 0, -0.3}], 
       Text[Style["0", 12], {-0.15, 0, 0}], 
       Text[Style["3/16", 12], {0.16, 0, 3/16}], 
       Text[Style["1/4", 12], {0.16, 0, 0.25}], 
       Text[Style["0.3", 12], {-0.13, 0, 0.3}], 
       Text[Style[label, labelSize, Bold], {0, 0, 0.45}]}, 
      ViewPoint -> {0, -1.5, 0}, Boxed -> False, 
      ImageSize -> {120, 300}], 
     Graphics3D[{LightBlue, Specularity[White, 20], Opacity[0.5], 
       Sphere[{0, 0, -0.4}, 0.11]}], 
     Graphics3D[{Red, Specularity[White, 20], 
       Sphere[{0, 0, -0.4}, 0.1]}], 
     Graphics3D[{LightBlue, Opacity[0.5], 
       Tube[{{0, 0, -0.4}, {0, 0, 0.35}}, 0.05]}], 
     Graphics3D[{Red, Specularity[White, 20], 
       Cylinder[{{0, 0, -0.45}, {0, 0, x}}, 0.04]}], 
     Graphics3D[{Thickness[0.015], 
       Line[{{-0.07, 0, #}, {-0.09, 0, #}}] & /@ 
        Table[i, {i, -0.3, 0.3, 0.1}]}], 
     Graphics3D[{Red, Thickness[0.015], 
       Arrow[{{0.09, 0, 3/16}, {0.03, 0, 3/16}}], 
       Arrow[{{0.09, 0, 0.25}, {0.03, 0, 0.25}}]}]}];

Mathematica graphics

Now you can't rotate it.

share|improve this answer
add comment

A not fully documented way:

Show[Graphics3D[..], Method -> {"RotationControl" -> None}]

The option can be added directly to Graphics3D, Plot3D, etc.


Edit: There is a (popup) context menu for modifying the view of Graphics3D objects. It's the one you right-click or control-click on the graphics. This menu can change the view point of the graphics. The only methods presented here (so far) that prevent this are Deploy, Overlay, Rojo's EventHandler one, and of course Rasterize. A different context menu pops up in those cases.


Edit 2: I found a way to take care of the context menu:

Style[
  Graphics3D[Cuboid[], Method -> {"RotationControl" -> None}],
  ContextMenu -> FEPrivate`FrontEndResource["ContextMenus", "Output"], 
  ComponentwiseContextMenu ->
    {"Graphics3DBox" -> FEPrivate`FrontEndResource["ContextMenus", "Output"]}]

You know, Deploy is easier, but some may find it interesting.

share|improve this answer
    
I'm not voting for this until you tell me how you found it. –  Mr.Wizard Jul 31 '13 at 20:46
    
@Mr.Wizard I don't recall. I'm afraid I might have guessed. I found Method -> {"RotationControl" -> ..}} by looking at "Show Expressions" of graphics functions output. I was trying to figure out why ParametricPlot3D rotates differently than Plot3D when manipulated with the mouse. None was probably a guess, or someone told me a long time ago. –  Michael E2 Jul 31 '13 at 20:58
1  
@Mr.Wizard There's also {"Globe", "ArcBall", "TrackBall"}, as can be seen in the example in Graphics3D's help –  Rojo Jul 31 '13 at 21:09
1  
Interestingly this doesn't work in version 7 but by agreement you get +1. :-) ("Show Expression" counts.) –  Mr.Wizard Jul 31 '13 at 21:56
1  
@Mr.Wizard and Michael — This is actually documented in Graphics3D and has been used before on this site (including once by Michael!) :) –  rm -rf Aug 1 '13 at 2:48
show 6 more comments

If rotation is all you want to suppress, but you still want zooming and panning, you could do

x = 0;
Slider[Dynamic[x], {-.3, .3}]
thermo[Dynamic@x, "\[Alpha]", 20]~Show~{
     ViewVertical -> Dynamic[{0, 0, 1}, Null &], 
     ViewPoint -> Dynamic[{0, -1, 0}, Null &]
  }

One could try to turn this into functions. I am not sure how well these work. AbsoluteOptions is know to be buggy.

dont[ops__][gr_] := 
 Show[gr, Quiet@AbsoluteOptions[
    gr, {ops}] /. (op : Alternatives[ops] -> Dynamic[i_, ___] | i_) :> (op -> 
      Dynamic[i, Null &])]

dontRotate[gr_Graphics3D] := dont[ViewPoint, ViewVertical][gr];
dontZoom[gr_Graphics3D] := dont[ViewAngle][gr];
dontPan[gr_Graphics3D] := dont[ViewCenter][gr];

Another way to do this if you haven't changed your hotkeys would be

EventHandler[thermo[x, "\[Alpha]", 20], "MouseDown" :> Null, 
 PassEventsDown :> Dynamic[
  CurrentValue["ControlKey"] || CurrentValue["ShiftKey"]]]

This last also works without the Dynamic but I guess the Futz would scold me if I used that form

share|improve this answer
    
Thank you. A good solution. I prefer the one given by Nasser, just since it enables to once define the function and use it after without any additions. –  Alexei Boulbitch Jul 31 '13 at 12:41
    
@AlexeiBoulbitch definately his solution is the standard most practical way to prevent user interaction. –  Rojo Jul 31 '13 at 14:28
    
(+1) Now all you need is a thermometer controller to connect to Mathematica! By the way, there is weakness in using Dynamic on view properties: If you right-click/control-click on the graphic, the popup menu gives several alternatives, some of which overwrite the settings and destroy the Dynamic expressions. –  Michael E2 Jul 31 '13 at 21:26
    
@MichaelE2, true, I had never seen, let alone used, those options. In that regard, your solution is quite unique, in that you can change the view through the menus and it is still unrotable. Nice –  Rojo Aug 1 '13 at 1:34
    
@Michael E2 It seems that while the approach of Rojo based on the dont... functions admits overriding using the right-click dynamic menu, his approach based on the EventHandler is free of that drawback, as well as the Nasser's approach. Am I right, or I missed something? –  Alexei Boulbitch Aug 1 '13 at 7:54
show 1 more comment

dont ovelook the simplest approach..

Rasterize[Graphics3D.. ]
share|improve this answer
    
Thank you, yes. In order not to suppress the Dynamic functionality Rasterize should be wrapped by Dynamic. Then the smoothness critically depends upon the RasterSize. I find RasterSize->200 yields a rather good compromise between smooth slider motion and the thermometer view. –  Alexei Boulbitch Aug 1 '13 at 8:11
add comment

Another simple solution is to replace Show by Overlay@List@Show.

share|improve this answer
    
Jens, you should try to hit 32,768 and take a picture. –  Mr.Wizard Aug 1 '13 at 19:03
    
Did you miss 2^16 ? I guess, then you'll have to wait until 2^17... Anyway, my current score is special too: 32612, read: 3, 2, 6, 12. Each is the product of the previous two! –  Jens Aug 1 '13 at 19:39
    
Yes, I did miss 2^16. Nice pattern you recognized; it would be an interesting game to try to find something special about the reputation number you end each day with. –  Mr.Wizard Aug 2 '13 at 1:41
add comment

An interesting side-note re: using the Method->None approach is that you can still zoom and pan w/ option/shift. Might not be desirable in all cases.

share|improve this answer
add comment

Your Answer

 
discard

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.