Appendix A
Matlab script: The harmonic cross-ratio model for interceptive paths
%FILTERING PROGRM ACCORDING Ying Ning’s dynamic filtering algorithm
% produced by W Kim 05/23/2016
%and plotting rtn for quiver velocity and direction
clear all;
%Coords=xlsread(’S15C3_s.xlsx’);
%Coords=xlsread(’fajen_sub1s.xlsx’);
Coords=xlsread(’Sub31_s.xlsx’);
%Coords=xlsread(’Sub35_s.xlsx’);
[m,n]=size(Coords);
b=2;
%m=115;
%%The harmonic cross-ratio model for interceptive paths
for i=1:m
A=[Coords(i,1);Coords(i,2)];
AV=[Coords(i,5);Coords(i,6)];
B=[Coords(i,3);Coords(i,4)];
BV=[Coords(i,7);Coords(i,8)];
ratio=norm(BV)/norm(AV);
slope=BV(2)/BV(1);
intercpt=B(2)-slope*B(1);
C=norm(BV)*[A;1]+norm(AV)*[B;1];
D=-norm(BV)*[A;1]+norm(AV)*[B;1];
center=C+D;
%radius=sqrt((C(1)/C(3)-center(1)/center(3))^2 + (C(2)/C(3)-center(2)/center(3))^2);
radius=norm(center(1:2)/center(3)-C(1:2)/C(3));
[xout,yout]=linecirc(slope,intercpt,center(1)/center(3),center(2)/center(3),radius);
inter=[xout;yout];
inter1=inter-[A,A];
%inserted on 9/1 2017 for the choice
if inter1(1,1) > 0
Coords(i,10:11)=inter1(:,1)’;
else
Coords(i,10:11)=inter1(:,2)’;
end
CV=[Coords(i,10);Coords(i,11)]/norm([Coords(i,10);Coords(i,11)]);
CVN=norm(AV)*CV;
Coords(i,10:11)=CVN’;
end
% set m=360
B=5;
%Coord(1:m,:)=[Coords(:,1:2),Coords(:,10:11)];
%Coord(m+1:2*m,:)=[Coords(:,1:2),Coords(:,5:6)];
%Coord(m+1:2*m,:)=[Coords(:,3:4),Coords(:,7:8)];
%quiver(Coords(1:B:n,1),Coords(1:B:n,2),Coords(1:B:n,5),Coords(1:B:n,6));
figure;
%we modified to overlab two plots
subplot(1,2,1)
quiver(Coords(1:b:m,3),Coords(1:b:m,4),Coords(1:b:m,7),Coords(1:b:m,8));
hold on
quiver(Coords(1:b:m,1),Coords(1:b:m,2),Coords(1:b:m,5),Coords(1:b:m,6));
quiver(Coords(1:b:m,1),Coords(1:b:m,2),Coords(1:b:m,10),Coords(1:b:m,11));
hold off
xlabel(’x/cm’);
ylabel(’Path and velocity of Cross Center (z/cm)’);
%quiver(Coord(1:B:2*m,1),Coord(1:B:2*m,2),Coord(1:B:2*m,3),Coord(1:B:2*m,4));
%quiver(Coord(1:B:m,1),Coord(1:B:m,2),Coord(1:B:m,3),Coord(1:B:m,4),.5,’--r’);
%quiver(Coord(1:B:m,1),Coord(1:B:m,2),Coord(1:B:m,3),Coord(1:B:m,4));
%Compute bearing angle
%bearing=heading-target angle
for i=1:m
headingA(i)=atan2(Coords(i,5),Coords(i,6));%agent haeding
headingM(i)=atan2(Coords(i,10),Coords(i,11));%model heading
%measure line of sight%
acoord=[Coords(i,1) Coords(i,2)];
tcoord=[Coords(i,3) Coords(i,4)];
%los=(tcoord-acoord)/norm(tcoord-acoord);
los=(tcoord-acoord);
linesight(i)=atan2(los(2), los(1));
CBM(1,i)=180*(headingA(i)-linesight(i))/pi;
CBM(2,i)=180*(headingM(i)-linesight(i))/pi;
end
time=[0:0.01:m*001];
subplot(1,2,2)
plot(time(1:m),-CBM(1,:),time(1:m),-CBM(2,:),’--’);
xlabel(’sec’);
ylabel(’Bearing Angle (deg)’);
legend(’Agent’,’Model’);