Message Boards Message Boards

Avoid problem while using ViewPoint in a Manipulate?

GROUPS:

Hi everyone,

I am making an app which shows a shaft and unbalanced masses coming off it with varying radii and locations along the length of the shaft: enter image description here

I need the user to be able to select between ViewPoint -> Right and ViewPoint -> Front so that they can set it up easily. I have set ViewPoint to a variable (viewPoint) inside Graphics3D and used that variable to populate a SetterBar in the usual way:

Manipulate[

 Graphics3D[

  Cylinder[{{0, 0, 0}, {0 + shaftLength, 0, 0}}, shaftRadius],

  ViewPoint -> viewPoint,
  ImageSize -> {500, 500},
  PlotRange -> {{0, shaftLength}, {-0.1, 0.1}, {-0.1, 0.1}},
  Boxed -> False

  ],

 {viewPoint, {Right, Front}},
 {{shaftLength, 1}, 0.1, 1},
 {{shaftRadius, 0.01}, 0.001, 0.05}

 ]

This works perfectly until I manually adjust the viewpoint with the mouse - which I also need the user to be able to do - and then the buttons stop responding.

Is this a bug, or can someone spot a mistake in my approach?

Thanks,

Si

POSTED BY: Simon Dee
Answer
1 month ago

I'm not 100% sure why it does not work as it should, perhaps someone else knows the cause. A solution would be to wrap viewpoint in a Dynamic:

ViewPoint -> Dynamic[viewPoint]

Note that you don't have to change PlotRange; it will be done automatically... Graphics3D always shows all the content unless specified otherwise...

POSTED BY: Sander Huisman
Answer
1 month ago

Thanks for your reply, Sander.

Your method changed the behaviour a bit, but it's still not working as expected. I've escalated this to Wolfram - I'll post in here if I find what the issue is.

POSTED BY: Simon Dee
Answer
1 month ago

You could use the Graphics3D option PreserveImageOptions. It is by default set to True. Which means that the graphics will "remember" any user interaction, and override further changes in view settings from the code. By setting the option to False, the graphics will respond to new changes in view settings from the code.

Manipulate[
 Graphics3D[
  Cylinder[{{0, 0, 0}, {0 + shaftLength, 0, 0}}, shaftRadius],
  ViewPoint -> viewPoint,
  ImageSize -> {500, 500},
  PlotRange -> {{0, shaftLength}, {-0.1, 0.1}, {-0.1, 0.1}},
  Boxed -> False, PreserveImageOptions->False
 ],
 {viewPoint, {Right, Front}},
 {{shaftLength, 1}, 0.1, 1},
 {{shaftRadius, 0.01}, 0.001, 0.05}
 ]

This will cause the view to be reset at any change in the Manipulate controls. Not only those that are aimed at controlling the view. Which can be seen as a drawback. There are methods to overcome this. But to paraphrase a judge in France, this post is too small.

POSTED BY: Hans Milton
Answer
1 month ago

Group Abstract Group Abstract