辅导maltab 编程、辅导matlab程序设计、辅导maltab

- 首页 >> Matlab编程

function ret = simulate_raptors (raptor_distance, vhuman, vraptor0, vraptor1, vraptor2, angle, nsteps)

h = [0.0, 0.0];

r0 = [0.0,1.0]*raptor_distance;

r1 = [-sqrt(3.)/2., -0.5]*raptor_distance;

r2 = [sqrt(3.)/2., -0.5]*raptor_distance;


tmax = 5.0;

raptor_min_distance = 0.2 ;

dt = tmax/nsteps;

t = 0.;

figure;

hold on;

for x=1:nsteps

       dh = derivative_h(vhuman, angle);

       dr0 = derivative_r0(h, r0, vraptor0);

       dr1 = derivative_r1(h, r1, vraptor1);

       dr2 = derivative_r2(h, r2, vraptor2);

       h = h + dh .*dt;

       r0 = r0 + dr0 .* dt;

       r1 = r1 + dr1 .* dt;

       r2 = r2 + dr2 .* dt;

%         plot(h(1), h(2), '*');

%         plot (r0(1), r0(2), '.');

%         plot (r1(1), r1(2), '+');

%         plot (r2(1), r2(2), 'o');

       plot(h(1), h(2), '*r');

       plot (r0(1), r0(2), '.b');

       plot (r1(1), r1(2), '+g');

       plot (r2(1), r2(2), 'ok');

       t = t + dt;

       if (norm(r0-h) <= raptor_min_distance) | (norm(r1-h) <= raptor_min_distance)| (norm(r2-h) <= raptor_min_distance)

           fprintf('time is %.2f and the angle is %.2f degree\n', t, angle*180/pi);

           break

       end

end

legend('human', 'r0', 'r1', 'r2')

ret = 1;


end


站长地图