Demo entry 6638992

CS314 HW1 Question1

Submitted by anonymous on Sep 09, 2017 at 01:16
Language: Matlab. Code size: 1.4 kB.

```function ret = simulate_raptors_Q1 (raptor_distance, vhuman, vraptor0, vraptor1, vraptor2, nsteps)
tmin = 0.0;
angle_final = 0.0;
for y = 0:360
t = 0;
h = [0.0, 0.0];
r0 = [1.0,0.0]*raptor_distance;
r1 = [-0.5,sqrt(3.)/2.]*raptor_distance;
r2 = [-0.5,-sqrt(3.)/2.]*raptor_distance;
tmax = 5.0;
raptor_min_distance = 0.2 ;

dt = tmax/nsteps;
grid on;
hold on;
angle_use = y / 180 * pi;
for x=1:nsteps
dh = derivative_h(vhuman, angle_use);
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');
t = t + dt;
if (norm(r0-h) <= raptor_min_distance) | (norm(r1-h) <= raptor_min_distance)| (norm(r2-h) <= raptor_min_distance)
if t > tmin
tmin = t;
angle_final = y;
fprintf('time is %f\n', t);
fprintf('y is %f\n', y);
end
break
end
end
end

fprintf('final time is %f\n', tmin);
fprintf('final angle is %f\n', angle_final)

ret = 1;

end
```

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.