1 | function [M, pts] = unoccluded2_motion(nframes,npoints,frot,ftrans) |
---|
2 | % This is an alternate motion generator. The previous one had the property that the |
---|
3 | % if, for each frame, one takes the third row of the rotation matrix, these all lie in |
---|
4 | % a plane. |
---|
5 | |
---|
6 | % To avoid this, we'll add a little torque to the old method. We'll rotate out of plane by |
---|
7 | % the same magnitude in another direction, but this time with angular acceleration. |
---|
8 | M = []; |
---|
9 | translation_mag = ftrans/(nframes-1); |
---|
10 | ip_rot = (pi/2)/(nframes-1); |
---|
11 | op_rot = (2*pi*frot)/(nframes-1); |
---|
12 | |
---|
13 | tor_rots = (0:nframes-1).*(1:nframes)./2; |
---|
14 | tor_rots = (2*pi*frot).*tor_rots./sum(tor_rots); |
---|
15 | tor_axis = 2*pi*rand(1); |
---|
16 | |
---|
17 | pts = rand(4,npoints); |
---|
18 | pts(4,:) = ones(1,npoints); |
---|
19 | % points have x,y,z coordinates, and a 1 in the 4th row for translation. |
---|
20 | |
---|
21 | depth_axis = 2*pi*rand(1); |
---|
22 | translation_dir = 2*pi*rand(1); |
---|
23 | translation_vec = translation_mag*[cos(translation_dir), sin(translation_dir),0]; |
---|
24 | |
---|
25 | rpts1 = rotate_z_axis(pts,depth_axis); |
---|
26 | |
---|
27 | for fnum=0:nframes-1 |
---|
28 | tor_rot = tor_rots(fnum+1); |
---|
29 | rpts2 = rotate_x_axis(rpts1,op_rot*fnum); |
---|
30 | rpts3 = rotate_z_axis(rpts2,-depth_axis); |
---|
31 | |
---|
32 | rpts3a = rotate_z_axis(rpts3,tor_axis); |
---|
33 | rpts3b = rotate_x_axis(rpts3a,tor_rot); |
---|
34 | rpts3c = rotate_z_axis(rpts3b,-tor_axis); |
---|
35 | |
---|
36 | rpts4 = rotate_z_axis(rpts3c,ip_rot*fnum); |
---|
37 | rpts5 = translate(rpts4,fnum*translation_vec); |
---|
38 | M = [M',rpts5(1:2,:)']'; |
---|
39 | end |
---|
40 | |
---|
41 | |
---|