[Date Index]
[Thread Index]
[Author Index]
Exporting video of simulation
*To*: mathgroup at smc.vnet.net
*Subject*: [mg116718] Exporting video of simulation
*From*: Gabriel Landi <gtlandi at gmail.com>
*Date*: Fri, 25 Feb 2011 06:33:59 -0500 (EST)
Hey guys,
I've been using Mathematica to do the following:
(1) Import data values from a simulation done in a different software.
Simulation is basically solving a ODE.
The data has the form (t, x1, x2, x3, ...)
(2) I then use this data to make a ParametricPlot3D of (x1(t), x2(t),
x3(t)). I Use function interpolation which works pretty well.
(3) Now... what I really want is to make a video of this parametric 3D plot
as a function of time. i. e., the 3D curve is drawn with time in the video.
So far, the best I have come up with is to create a Manipulate Object and
then export it (almost aways to quicktime .mov even though the format
doesn't matter).
I also plot alongside the 3D plot a 2D graph of one of the components.
The problem is: making the video takes alot more time than the simulation.
It takes over 1/2 hour.
The reason, which I believe it is, is that each frame is constructed by
completely re-ploting the graph.
In other words, if one frame has the plot from t0 to t1 and the next has the
plot from t0 to t2, then Mathematica makes 2 different graphs.
I was wondering if there was a way to "AppendTo" the plot so he doesn't
construct a new graph object.
Also, overall, I am kindly asking for any tips you guys might have on this
subject.
Notebook is given below. It has been condensed into a single function which
takes as only parameter the part of the file name that I want to produce the
video (I have several files named sequentially).
File is also pretty big, around 30 MB and so the line
*data = Take[import, {1,-1,2000}] *
is used to make it a little bit lighter.
Thank you all in advance.
Gabriel
videoer[i_] :=
Module[{data, ani, t0, fx, fy, fz, t, t2, tf, dt, T, import, h, opt},
opt = {LabelStyle -> Directive["Times", 16], Frame -> True,
FrameStyle -> Directive[16, "Times"]};
import =
Most[Drop[Import["h0_" <> ToString[i] <> "-phi_0.dat", "Table"], 2]];
data = Take[import, {1, -1, 2000}];
Print["Import Done"];
t0 = data[[1, 1]]; t2 = data[[2, 1]]; tf = data[[-1, 1]]; dt = t2 - t0;
fx = Interpolation[data[[All, {1, 2}]]];
fy = Interpolation[data[[All, {1, 3}]]];
fz = Interpolation[data[[All, {1, 4}]]];
h = Interpolation[data[[All, {1, 8}]]];
ani = Manipulate[Grid[{{
Plot[{h[t], fz[t]}, {t, t0, T},
PlotRange -> {{t0, tf}, If[i <= 1, {-1, 1}, {-i, i}]},
ImageSize -> 250, PerformanceGoal -> "Quality", opt,
PlotStyle -> {Directive[Black, Thickness[0.007]], Red}],
Show[
Graphics3D[{
Style[Sphere[{0, 0, 0}, 0.2], Red],
{Black, Arrowheads[0.05],
Arrow[Tube[{{0, 0, 0}, {fx[T], fy[T], fz[T]}}]]},
Line[{{0, 0, -1.5}, {0, 0, 1.5}}],
Line[{{0, -1.5, 0}, {0, 1.5, 0}}],
Line[{{-1.5, 0, 0}, {1.5, 0, 0}}]
}, Boxed -> False,
PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}, {-1.5, 1.5}},
ViewPoint -> {Pi, Pi, 1}
],
ParametricPlot3D[{fx[t], fy[t], fz[t]}, {t, t0, T},
MaxRecursion -> Infinity, PerformanceGoal -> "Quality"]
, ImageSize -> 400]
}}]
,
{T, t2, tf}, Bookmarks -> {"start" :> (T = t2), "stop" :> (T = tf)}];
Print["Manipulate Object Construction Complete"];
Export["./Videos/vid_H_" <> ToString[i] <> ".mov", ani,
"AnimationDuration" -> 20., "FrameRate" -> 15.]
]
Prev by Date:
**Re: weibull plot on weibull scaled paper**
Next by Date:
**Re: FinancialData Function Not Working for Property "Members"**
Previous by thread:
**Re: Getting an image with JLink**
Next by thread:
**Re: Exporting video of simulation**
| |