Message Boards Message Boards

1
|
7503 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

How can I change the orientation of a 3D object after using Dynamic?

Posted 10 years ago

While going over the examples in the tutorial "Advanced Manipulate Functionality" I'm struggling with the apparent ramifications of improving

Manipulate[
 Plot3D[Sin[n x y], {x, 0, 3}, {y, 0, 3}, ViewPoint -> {2, v, 2}, 
  SphericalRegion -> True, Ticks -> None], {n, 1, 4}, {v, -2, 2}]

by using "Dynamic" as directed:

Manipulate[
 Plot3D[Sin[n x y], {x, 0, 3}, {y, 0, 3}, 
  ViewPoint -> Dynamic[{2, v, 2}], SphericalRegion -> True, 
  Ticks -> None], {n, 1, 4}, {v, -2, 2}]

I see that the improvement works as stated. However, with the "Dynamic" version I can no longer use the mouse to change the orientation of the 3D figure. When attempting to change the orientation with the mouse I get a zillion identical errors stating

         Set::setraw: Cannot assign to raw object 2. >>

How can I use the "Dynamic" version but still be able to change the orientation of the figure with the mouse? (I'm using Wolfram Mathematica 10.0.0.0 with Windows 7.)

POSTED BY: Jim Baldwin
3 Replies

Ok. I tried the updated code. There are no errors, but you can't manipulate the orientation of the graphic with the mouse. When I attempt to drag the graphic, the graphic switches to the low-res version, and the chasing arrows appear, just like it would if direct manipulation would work. However, the graphic will not rotate. I suppose that the user would like to be able to have free (user drag) rotation grind one of the other two axes, although the code seems to manipulate only viewpoint, not the underlying orientation of the graphic.

Note that using the shift key works to change the location of the graphic, and using the option key lets you zoom in and out.

I suppose, though, that if you have a widget to control rotation, you really would not want to then be able to directly manipulate the image. I had a similar problem with keeping stereo images in sync, and I will use the suggested code to solve my problem.

When you change the ViewPoint, it's trying to do the following:

{2,v,2} = {2.1, 2.5, 2.3} (* where 2.1, 2.5, and 2.3 are whatever random values your rotation produced *)

which isn't going to work. You can use the second argument of Dynamic to provide a custom setter function.

Manipulate[
 Plot3D[Sin[n x y], {x, 0, 3}, {y, 0, 3}, 
  ViewPoint -> Dynamic[{2, v, 2}, (v = Clip[#[[2]], {-2, 2}]) &], 
  SphericalRegion -> True, Ticks -> None], {n, 1, 4}, {v, -2, 2}]
POSTED BY: John Fultz
Posted 10 years ago

Thank you, John!

From your explanation (what I suppose I should have understood from reading the documentation on Dynamic), I now understand why those errors occurred. My superficial understanding as to how Manipulate works is now a little less superficial but I think I've got a long way to go (as in understanding why the new issue occurs that George brings up).

Thanks again!

POSTED BY: Jim Baldwin
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