annotate +anim/animate.m @ 87:0a29a60e0b21

In Curve: Rearranged for speed. arc_length_fun is now a property of Curve. If it is not supplied, it is computed via the derivative and spline fitting. Switching to the arc length parameterization is much faster now. The new stuff can be tested with testArcLength.m (which should be deleted after that).
author Martin Almquist <martin.almquist@it.uu.se>
date Sun, 29 Nov 2015 22:23:09 +0100
parents 4cd77c7bdcaf
children 6ec2248b83c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
1 % Calls F(t) repeatedly
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
2 % Should there be a Fsetup and a F, two function, to allow creating a plot and then updating it?
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
3 % F takes the time to generate the frame for and returns the actual time for the generated frame.
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
4 % t = F(t_r) is a function that paints a frame for time t. t is the closest time <=t_r
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
5 % it will be called for increasnig t.
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
6
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
7 %Todo: make it catch up and produce warnings if it lags behind? Instead of just requesting the next target time
79
4cd77c7bdcaf Fixed bug in anim.animate for starting times != 0.
Jonatan Werpers <jonatan@werpers.com>
parents: 71
diff changeset
8 function animate(F, tstart, tend, time_modifier , frame_rate)
0
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
9 if ~exist('time_modifier')
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
10 time_modifier = 1;
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
11 end
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
12
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
13 if ~exist('frame_rate')
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
14 frame_rate = 30;
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
15 end
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
16
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
17 frame_time = 1/frame_rate;
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
18 dt = frame_time*time_modifier;
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
19
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
20 animation_start = tic();
79
4cd77c7bdcaf Fixed bug in anim.animate for starting times != 0.
Jonatan Werpers <jonatan@werpers.com>
parents: 71
diff changeset
21 t = F(tstart);
0
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
22 while t < tend
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
23 t = F(t + dt);
79
4cd77c7bdcaf Fixed bug in anim.animate for starting times != 0.
Jonatan Werpers <jonatan@werpers.com>
parents: 71
diff changeset
24 t_left = (t-tstart)/time_modifier-toc(animation_start);
0
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
25 pause(t_left)
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
26 end
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
27 time_to_animate = toc(animation_start);
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
28 expected_time = tend/time_modifier;
71
1edee9e1ea41 Updated printing stuff for animation functions.
Jonatan Werpers <jonatan@werpers.com>
parents: 0
diff changeset
29
1edee9e1ea41 Updated printing stuff for animation functions.
Jonatan Werpers <jonatan@werpers.com>
parents: 0
diff changeset
30 fprintf('\n');
0
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
31 fprintf('Time to animate: %.3f\n', time_to_animate)
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
32 fprintf('Expected time : %.3f\n', expected_time)
48b6fb693025 Initial commit.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
33 end