2
$\begingroup$

I have this ParametricPlot3D

sigma = 10;
rho = 27;
beta = 8/3;
sol = NDSolve[{x'[t] == sigma (y[t] - x[t]), 
    y'[t] == x[t] (rho - z[t]) - y[t], z'[t] == x[t] y[t] - beta z[t],
     x[0] == 0, y[0] == 1, z[0] == 1.05}, {x, y, z}, {t, 0, 100}, 
   MaxSteps -> 30000];
p = ParametricPlot3D[Evaluate[{x[t], y[t], z[t]} /. sol], {t, 0, 100},
   ColorFunction -> Function[{x, y, z}, Hue[x]], PlotPoints -> 250]

enter image description here

I would like to extract the data points in the form of a list {{x1,y1,z1},{x2,y2,z2},...} and so I did this

data = Cases[p, GraphicsComplex[x__] -> x, {1}][[1]]; 

But the points do not seem to be in the right order, in fact the first number is not my inizial value (0,1,1.05), nor is the last one. If I do

Graphics3D@Line@data

this is the result

enter image description here

which is all messed up. How can I extract the points from the plot in the right order?

$\endgroup$
  • 4
    $\begingroup$ Try this: data = Cases[Normal[p], Line[pts_] :> pts, ∞][[1]]. $\endgroup$ – J. M. will be back soon Mar 24 '17 at 15:28
  • $\begingroup$ Wow, that worked, thank you very much! Could you explain your code a little bit, what is Normal doing exactly and why using RuleDelayed instead of the usual rule? $\endgroup$ – Emmet Mar 24 '17 at 15:34
  • 2
    $\begingroup$ maybe missing the point of the question, but you can ge the points right from the NDSolve result: Graphics3D@Line[Transpose[Through[{x, y, z}["ValuesOnGrid"]] /. First@sol ]] $\endgroup$ – george2079 Mar 24 '17 at 15:52
  • 2
    $\begingroup$ Plot can give you fewer points as needed to generate a smooth curve. (Example if you set a small MaxStepSize in NDSolve, Plot will just take the points it needs.). In this case about the same.. I kind of like having the actual calculated points, not interpolated. $\endgroup$ – george2079 Mar 24 '17 at 16:13
  • 1
    $\begingroup$ @george2079 I see, good point. If anybody is curious, in this case using data2 = Transpose[Through[{x, y, z}["ValuesOnGrid"]] /. First@sol] I get 12520 points while data = Cases[Normal[p], Line[pts_] :> pts, ∞][[1]] gives me 13110. $\endgroup$ – Emmet Mar 24 '17 at 16:23

Your Answer

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

Browse other questions tagged or ask your own question.