Ugly rendering of curve with ParametricPlot3D and NDSolve [closed]

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

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 KlettMar 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.

• 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. – m_goldberg Mar 6 '16 at 14:51
• 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. – Cham Mar 6 '16 at 14:54
• How can I, or anybody else, know the lines are artifacts when you don't post the code you used to generate the image? – m_goldberg Mar 6 '16 at 14:58
• 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 ? – Cham Mar 6 '16 at 15:00
• 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. – 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
];
ParametricPlot3D[
r[t] /. p, {t, 0, T}, PlotPoints -> pts, PlotStyle -> Green,
Background -> Black, PlotRange -> All, Boxed -> False, Axes -> False
]
]


With pts = 50,

With pts = 500,

EDIT

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

Do[
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,

When rec=15,

• 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 ? – Cham Mar 6 '16 at 16:06
• Module has no advantage here; I just like to use it. – thedude Mar 6 '16 at 16:20
• 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). – Cham Mar 6 '16 at 16:24