2
$\begingroup$

I am creating a series of "apps" as study aids for the Engineering Statics course that I teach. I am usually able to solve most of my "problems", but I am stuck on a simple one. The code below allows a user to visualize a 3D force vector that has its position controlled with two angles, a1 rotates the plane that contains the line of action of the vector about the z-axis and b1 rotates the vector out of the xy-plane.

The user can use the mouse to rotate (LMB), pan (Shift+LMB) and zoom (Ctrl+LMB) the graphics. When the user adjusts the manipulate sliders the rotation and pan settings remain unchanged, but the graphic "snaps" back the the default zoom setting. I would like to prevent the zoom reset.

I am sure that I am missing something simple, but I have been unable to find a post that mentions this issue. If someone has a solution, I would greatly appreciate it if they would pass it along.

A second small issue... does anyone know how I could add the degree symbol to the label of the slider?

cd[x_] := Cos[x*\[Pi]/180.0];
sd[x_] := Sin[x*\[Pi]/180.0];
r = 10;
Manipulate[
 Graphics3D[{
   Style[InfinitePlane[{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}}], 
FaceForm[{LightGray, Opacity[0.2]}]],
   Style[HalfPlane[{{0, 0, -1}, {0, 0, 1}}, {cd[a1 ], sd[a1 ], 0}], 
FaceForm[{LightGray, Opacity[0.2]}]],
   Style[Arrow[{{0, 0, 0}, 
  f*{cd[b1 ] cd[a1], cd[b1] sd[a1], sd[b1]}}], Black, Thick],
   Style[Cuboid[{0, 0, 0}, f*{cd[b1 ] cd[a1], cd[b1] sd[a1], sd[b1]}],
 Opacity[0.01], EdgeForm[Directive[Thin, Gray]]],
   },
  PlotRange -> {{-r, r}, {-r, r}, {-r, r}},
  Boxed -> False,
  Axes -> True,
  AxesOrigin -> {0, 0, 0},
  BoxRatios -> {4, 4, 3},
  AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}},
  ViewProjection -> "Orthographic",
  SphericalRegion -> True,
  Method -> {"RotationControl" -> Dynamic@"Globe"}
  ],
 Control[{{a1, 30, "\[Theta]"}, 0, 360, Appearance -> "Labeled", 
ControlType -> Slider}],
 Control[{{b1, 30, "\[Phi]"}, -90, 90, Appearance -> "Labeled", 
ControlType -> Slider}],
 Control[{{f, 10, "\!\(\*SubscriptBox[\(F\), \(mag\)]\)"}, 1, 10, 
Appearance -> "Labeled", ControlType -> Slider}],
 TrackedSymbols :> {a1, b1, f}]

enter image description here

$\endgroup$
1
$\begingroup$

The best solution in this case will be to not recreate whole Graphics3D when th slider is manipulated. It can be done by simply adding Dynamic to the primitives inside (lookup 'nesting dynamic' to learn more).

Like so:

... Style[ Dynamic @ HalfPlane[...

A second small issue... does anyone know how I could add the degree symbol to the label of the slider?

You can provide your controller layout explicitly, e.g.:

Control[
  {{a1, 30, "θ"}, 0, 360, Row[{Slider[##], Spacer[5], #, Degree}] &}
]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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