2
$\begingroup$

I'd like to have a SphericalPlot3D show up with the "z-axis" oriented horizontally by default. For example, in

With[{asz = 1,
  toff = 0.1,
  axes = Graphics3D[{
     Red, Arrow[Tube[{{0, 0, 0}, {asz, 0, 0}}] , 0.05],
     Blue, Arrow[Tube[{{0, 0, 0}, {0, asz, 0}}] , 0.05],
     Darker[Green, .8], Arrow[Tube[{{0, 0, 0}, {0, 0, asz}}] , 0.05],
     Text[ "\!\(\*SubscriptBox[\(e\), \(1\)]\)",  {asz + toff, 0, 0} ],
     Text[ "\!\(\*SubscriptBox[\(e\), \(2\)]\)",  {0, asz + toff, 0} ],
     Text[ "\!\(\*SubscriptBox[\(e\), \(3\)]\)",  {0, 0, asz + toff} ]
     }],

  U = ((Cos[Pi #2 Cos[#1]] - Cos[Pi #2])/Sin[#1])^2 & },

 Show[
  SphericalPlot3D[
   U[t, 1]
   , {t, 0, Pi}, {p, 0, 2 Pi}
   , PlotRange -> Full
   , PlotStyle -> Directive[Opacity[0.7]]
   , ImageSize -> 400
   ],
  axes]
 ]

my arrow labeled "e_3" points "upwards" in the graphics view.

SphericalPlot3D sample

I can rotate the image with the mouse, but would like it to be in the horizontal, pointing to the right, without using the mouse.

$\endgroup$
  • 2
    $\begingroup$ What about SetOptions in combination with ViewPoint and ViewVertical ? $\endgroup$ – Yves Klett Mar 1 '15 at 16:27
3
$\begingroup$

another option is to do this by changing viewPoint, ViewVertical,ViewAngle. There are lots of view point dynamic selectors, I use one I found on this thread http://forums.wolfram.com/mathgroup/archive/2009/Apr/thread.html#00504 by Alexander Elkins. The idea is to use the mouse to change the 3D until you get the position you want, then copy the values and use them in your code, so that the 3D shape will always have that orientation.

For example, in your case, here are the values needed

Mathematica graphics

And here is the code below. So you can now use these numbers in your original code.

Manipulate[
 axes = Graphics3D[{Red, Arrow[Tube[{{0, 0, 0}, {asz, 0, 0}}], 0.05], Blue, Arrow[Tube[{{0, 0, 0}, {0, asz, 0}}], 0.05], 
    Darker[Green, .8], Arrow[Tube[{{0, 0, 0}, {0, 0, asz}}], 0.05], Text["\!\(\*SubscriptBox[\(e\), \(1\)]\)", {asz + toff, 0, 0}], 
    Text["\!\(\*SubscriptBox[\(e\), \(2\)]\)", {0, asz + toff, 0}], Text["\!\(\*SubscriptBox[\(e\), \(3\)]\)", {0, 0, asz + toff}]},
   Axes -> Dynamic[axes],
   Boxed -> Dynamic[boxed],
   ImageSize -> 300
   ];
 U = ((Cos[Pi #2 Cos[#1]] - Cos[Pi #2])/Sin[#1])^2 &;
 Show[
  SphericalPlot3D[U[t, 1], {t, 0, Pi}, {p, 0, 2 Pi},
   PlotRange -> Full,
   PlotStyle -> Directive[Opacity[0.7]],
   ImageSize -> 400,
   ViewPoint -> Dynamic[vp],
   ViewVertical -> Dynamic[vv],
   ViewAngle -> Dynamic[va],
   ViewCenter -> Dynamic[vc],
   SphericalRegion -> Dynamic[sr],
   Method -> {"RotationControl" -> Dynamic[rc]}
   ], axes],
 {{vp, ViewPoint /. Options[Graphics3D], "ViewPoint\[Rule]"}, InputField}, {{vv, {0, 0, 1}, "ViewVertical\[Rule]"}, InputField},
 {{va, Automatic, "ViewAngle\[Rule]"}, InputField}, {{vc, {{1/2, 1/2, 1/2}, {1/2, 1/2}}, "ViewCenter\[Rule]"}, InputField},
 Row[{Labeled[Checkbox[Dynamic[sr]], "SphericalRegion\[Rule]", Left, Spacings -> 0],
   Labeled[Checkbox[Dynamic[axes]], "Axes\[Rule]", Left, Spacings -> 0], 
   Labeled[Checkbox[Dynamic[boxed]], "Boxed\[Rule]", Left, Spacings -> 0], 
   Labeled[Checkbox[Dynamic[tube]], "Tube\[Rule]", Left, Spacings -> 0]}], {sr, {True, False}, None},
 {axes, {False, True}, None}, {boxed, {False, True}, None}, {tube, {False, True}, None},
 {{rc, "ArcBall", "RotationControl\[Rule]"}, {"ArcBall", "Globe"}}]
$\endgroup$
4
$\begingroup$
sp3d = With[{asz = 1, toff = 0.1}, With[{axes =  Graphics3D[{Red, 
       Arrow[Tube[{{0, 0, 0}, {asz, 0, 0}}], 0.05], 
       Blue, Arrow[Tube[{{0, 0, 0}, {0, asz, 0}}], 0.05], 
       Darker[Green, .8], Arrow[Tube[{{0, 0, 0}, {0, 0, asz}}], 0.05],
        Text["\!\(\*SubscriptBox[\(e\), \(1\)]\)", {asz + toff, 0, 0}], 
        Text["\!\(\*SubscriptBox[\(e\), \(2\)]\)", {0, asz + toff, 0}], 
        Text["\!\(\*SubscriptBox[\(e\), \(3\)]\)", {0, 0, asz + toff}]}], 
       U = ((Cos[Pi #2 Cos[#1]] - Cos[Pi #2])/Sin[#1])^2 &}, 
   Show[SphericalPlot3D[U[t, 1], {t, 0, Pi}, {p, 0, 2 Pi}, 
     PlotRange -> Full, PlotStyle -> Directive[Opacity[0.7]], ImageSize -> 400], axes]]];

Show[MapAt[GeometricTransformation[#, RotationTransform[ Pi/2, {0, 1, 0}]] &, 
  sp3d, {1}], PlotRange -> All, ImageSize -> 300]

enter image description here

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