I am trying to write a Mathematica script that can interpolate a discrete vector field to a continuous vector field. I then want to extract the integral curves (field lines) from the continuous vector field.
I know that Mathematica's ListStreamPlot
function can visually present integral curves; however, I need the actual points that comprise them.
I have considered writing a brute-force method to the following effect: It seems that the integral curve could be determined recursively. If a point were picked in the list, then the "next" point in the integral curve would be that with the closest slope. (Each "point" is actually a vector, and thus each has its own slope.) There are only 4 candidates for the "next" point -- up, down, left, or right of the current point. The "next" point would then become the new starting point, and the process would recurse until the edge of the grid is reached.
However, I wonder if there is a simpler method using Mathematica's higher-level functions. (I also don't know if my method is even conceptually correct.)
I would really appreciate any thoughts or suggestions on this task.
Thanks!
FYI: http://mathematica.stackexchange.com
Make up some data:
data = Table[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3, 0.2}, {y, -3, 3, 0.2}];
Build a ListStreamPlot
plot = ListStreamPlot[data,
StreamStyle -> "Line", Frame -> False, PlotRangePadding -> 0]
In Mathematica everything is an expression - so even this plot is basically visualized code of graphics primitives. You can extract those primitives - including lines you need - by various ways. For example - just picking parts of expression you cam find all points comprising this plot:
points = plot[[1, 2, 1]];
If you need to see the whole expression evaluate plot//InputForm
. Now you could also do pattern matching to see inside expression. lets find all indexes comprising all your lines:
indexes = Cases[plot, Line[index_] -> index, Infinity];
Now you have everything to analyse, draw and stylize your lines. For example - design an app that highlights a specific line in the original plot:
Animate[Show[
plot,
Graphics[{Red, Opacity[.5], , Thickness[.02],
Line[points[[indexes[[k]]]]]}]]
, {{k, 1, "lines"}, 1, Length[indexes], 1}, FrameMargins -> 0]