I frequently have this graphics output problem :

I draw a 3D curve using NDSolve, and depending on the initial data, there's no way I could predict the shape and extent of the curve in 3D space. In the ParametricPlot3D code, I could use PlotRange -> All to show the whole curve, but then the 3D box isn't centered on the origin : {0, 0, 0}. Rotating the view is annoying in this case. I could use something like

PlotRange -> {{-100, 100}, {-100, 100}, {-100, 100}},

but most of the time the box is too small or too large to display the whole curve. The scale isn't adequate and there's no way I could predict in advance which scale should be best to show all the curve (and no more useless space, since it could be a pain to zoom in).

Using FindMax, I could find the fartest distance to the curve, from the origin, and use that value in PlotRange, but this may have a strong impact on performances in a Manipulate box (depending on the curve/solution complexity). I much prefer to use another way to show the whole curve.

So my question is this :

Using PlotRange (or another option ?), how can we tell Mathematica to show the whole curve, while maintaining the central view position on the origin ({0, 0, 0}) ?

EDIT : An example of a curve not centered on the origin :

    {Sin[3 t] - 2, Cos[5 t], 0.03 t},
    {t, 0, 2Pi},
    PlotRange -> All, (* Not good in this case *)
    Boxed -> True,
    ViewVector -> {0, 0, 0} (* Ugly option *)

I need to show all that curve, while fixing the view centered on the origin, and have a symetrical box all around the origin.

  • $\begingroup$ Have you tried ViewVector? This maintainces the view Position on the origin. $\endgroup$ – Kay Mar 25 '16 at 18:27
  • $\begingroup$ How ? Can you give a simple example of its use ? The documentation isn't very helpfull for these things ; it always give useless and fancy examples ! $\endgroup$ – Cham Mar 25 '16 at 18:28
  • $\begingroup$ Could you give an example of you curve? Btw, the 2. option you might Need is ViewAngle. This changes the visible range, without need of adjusting PlotRange etc. $\endgroup$ – Kay Mar 25 '16 at 18:30
  • $\begingroup$ Yes, I know the ViewAngle option, but then the problem is still the same : how to define a proper scale ? $\endgroup$ – Cham Mar 25 '16 at 18:32
  • $\begingroup$ Just a quick example : ParametricPlot3D[ {Sin[3 t] - 2, Cos[5 t], 0.03 t}, {t, 0, 10 Pi}, PlotRange -> All, Boxed -> True, ViewVector -> {0, 0, 0} ]. $\endgroup$ – Cham Mar 25 '16 at 18:32

first make the plot and use AbsoluteOptions to get the range:

p=ParametricPlot3D[{Sin[3 t] - 2, Cos[5 t], 0.03 t}, {t, 0, 2 Pi}, 
  PlotRange -> All,(*Not good in this case*)Boxed -> True, 
  ViewVector -> {0, 0, 0} (*Ugly option*)];(*<-this semicolon will be red, is ok*)
rad = Max@Abs@Flatten[ (PlotRange /. AbsoluteOptions[p])]

now combine the plot with a sphere ( or a cube or whatever ) that is centered and encompasses the figure.

Show[{Graphics3D[{Opacity[.1], Sphere[{0, 0, 0}, rad]}], p}]

You can set Opacity[0] here if you don't want to see the sphere at all..but I think it sort of helps anyway.

enter image description here

drawing axes is another option:

Show[{Graphics3D[{Arrowheads -> {-.02, .02}, 
    Arrow[{-#, #}] & /@ Permutations[{0, 0, rad}]}], p}, Boxed -> False]

enter image description here

  • $\begingroup$ This solution is hard to apply to a numerical curve found with NDSolve, that may change inside a Manipulatebox. And is has a cost on performance. $\endgroup$ – Cham Mar 25 '16 at 19:09
  • 1
    $\begingroup$ You can put all that in Mainpulate. I think it doesn't add much overhead to generating the plot in the first place.. give it a try. Or put up a real example. $\endgroup$ – george2079 Mar 25 '16 at 19:20
  • $\begingroup$ just noticed I forgot to assign the plot to p.. fixed. Hope that didn't confuse. $\endgroup$ – george2079 Mar 25 '16 at 19:47
  • $\begingroup$ It's working. I'll study this. $\endgroup$ – Cham Mar 25 '16 at 20:47
  • $\begingroup$ Since I don't want the sphere, this appears to work : rad = Max[Abs[Flatten[(PlotRange/.AbsoluteOptions[graphicsName])]]]; Show[graphicsName, PlotRange -> rad{{-1, 1}, {-1, 1}, {-1, 1}}]. But I don't understand the AbsoluteOptions. Could you add some comments in your answer about what your code is doing ? $\endgroup$ – Cham Mar 25 '16 at 20:50

If I got that right I suggest the following solution for your example:

ParametricPlot3D[{Sin[3 t], Cos[5 t], 0.03 t}, {t, 0, 1 Pi}, 
 PlotRange -> Full, Boxed -> True, ViewAngle -> 20 Degree, 
 ViewVector -> {{0, -5, 5}, {0, 0, 0}}]

Now, play with the ViewAngle to adjust the angle of view... enter image description here

  • $\begingroup$ You changed the function, which is now centered, so you have eliminated the source of the problem ("throwing the baby with the bath water"). Add "-2" to the "x" component. Your solution doesn't work. $\endgroup$ – Cham Mar 25 '16 at 19:00
  • $\begingroup$ Sry, my mistake. Didn't realized, that I throw something important away... $\endgroup$ – Kay Mar 25 '16 at 19:18

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.