I frequently have this rendering problem when I plot a complicated curve with ParametricPlot3D, found by solving a differential equation with NDSolve :

Ugly curve

The curve should be more "regular" (it is showing the motion of a charged particle around some magnetic field lines). I've indicated in red the typical artifacts I'm getting. And yet, in ParametricPlot3D, I'm using options like these :

PlotPoints -> 1000,
MaxRecursion -> 7,
PerformanceGoal -> "Quality"

In NDSolve, I'm using these options :

Method -> ExplicitRungeKutta,
PrecisionGoal -> 7,
MaxSteps -> 1000000,

So what may be wrong ? How can I get a better graphical output of the curve, without the glitches and straight line artifacts shown on the picture above ?

EDIT : You can see some of the artifacts I'm describing if you play a bit with the code from this demonstration (you need to lower the "velocity" and "distance", using the Manipulate sliders.) : http://demonstrations.wolfram.com/DipoleFieldsAreComplicated/

My own code is more complicated than this demo (this is why I don't provide a MWE example here), but the artifacts are the same.


closed as off-topic by m_goldberg, user9660, Michael E2, MarcoB, Yves Klett Mar 6 '16 at 17:53

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – m_goldberg, Community, MarcoB, Yves Klett
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ This is an ill-posed question. You do not provide sufficient code to reproduce the problem. You do not even clearly state what you don't like about the plot. Saying that the curves are ugly is not sufficient -- "ugly" is not a technical term. $\endgroup$ – m_goldberg Mar 6 '16 at 14:51
  • 2
    $\begingroup$ I think the picture says it all. By "ugly", I mean an output that isn't "right". See the straigth line artifacts on the picture above. $\endgroup$ – Cham Mar 6 '16 at 14:54
  • $\begingroup$ How can I, or anybody else, know the lines are artifacts when you don't post the code you used to generate the image? $\endgroup$ – m_goldberg Mar 6 '16 at 14:58
  • 2
    $\begingroup$ Because it's obvious if you examine the picture ! See the straight lines there ? They shouldn't be there. The curve is "regular" (rotation around some magntic field lines). Should I change that picture by adding some red arrows to point to the artifacts ? $\endgroup$ – Cham Mar 6 '16 at 15:00
  • 1
    $\begingroup$ You seem to think people reading your post have ESP and know everything about your problem that you do. That is not the case. I could not tell your plot was "The curve is 'regular' (rotation around some magntice field lines)" just by looking at it. It is your responsibility to ask a clear and complete question. $\endgroup$ – m_goldberg Mar 6 '16 at 15:05

Since you haven't provided any code, I wrote one for a particle in magnetic field to replicate the error:

Module[{T = 10^-2, pts = 50, k = 10^4},
 x = r[t].{1, 0, 0}; y = r[t].{0, 1, 0}; z = r[t].{0, 0, 1};
 B1[x_, y_, z_] = x {1, 1, 0};
 p = NDSolve[
   {-r''[t] == k Cross[r'[t], B1[x, y, z]], r[0] == {2, 1, -1}, 
    r'[0] == {0, 10^3, 0}}, r[t], {t, 0, T}, PrecisionGoal -> 5
  r[t] /. p, {t, 0, T}, PlotPoints -> pts, PlotStyle -> Green, 
  Background -> Black, PlotRange -> All, Boxed -> False, Axes -> False

With pts = 50,

enter image description here

With pts = 500,

enter image description here


Regarding your question about MaxRecursion, you can see that increasing rec does not help if PlotPoints is set low enough:

 Module[{T = 0.3 10^-2, pts = 20, k = 10^4}, 
x = r[t].{1, 0, 0}; y = r[t].{0, 1, 0}; z = r[t].{0, 0, 1};
B1[x_, y_, z_] = x {1, 1, 0};
p = NDSolve[{-r''[t] == k Cross[r'[t], B1[x, y, z]], 
    r[0] == {2, 1, -1}, r'[0] == {0, 10^3, 0}}, r[t], {t, 0, T}, 
    PrecisionGoal -> 5];
Print@ParametricPlot3D[r[t] /. p, {t, 0, T}, PlotPoints -> pts, 
    MaxRecursion -> rec, PlotStyle -> Lighter@Purple, Background -> Black, 
    PlotRange -> All, Boxed -> False, Axes -> False, 
    ImageSize -> 1000]],
 {rec, 0, 15}

When rec=3,

enter image description here

When rec=15,

enter image description here

  • $\begingroup$ Yes, that's the kind of artifacts I was talking about. But now, I'm not sure anymore of the meaning of PlotPoints. And what about MaxRecursion ? And by the way, why the Module, instead of declaring each parameter separately ? What are the advantages of Module ? $\endgroup$ – Cham Mar 6 '16 at 16:06
  • $\begingroup$ Module has no advantage here; I just like to use it. $\endgroup$ – thedude Mar 6 '16 at 16:20
  • $\begingroup$ Ok, thanks. Removing MaxRecursion and using PlotPoints -> ControlActive[200, 5000] appears to solve my issue (5000 points ?). Now I'm not sure when I should add MaxRecursion to my codes. I believed it was necessary when the curve has lots of tiny parts, like in the example above (path in a magnetic field). $\endgroup$ – Cham Mar 6 '16 at 16:24

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