% mfile GetFishDirection % compute force on fish % start with random direction force = randn(d,d) + II * randn(d,d); % add in electrostatic repulsion from sharks % sharkpnt points to sharks sharkpnt = find(shark(2:d+1,2:d+1)); % sharkwhere contains shark locations (as complex numbers) sharkwhere = ZZ(sharkpnt); nsharks = length(sharkwhere); % fishpnt points to fish fishpnt = find(fish(2:d+1,2:d+1)); % fishwhere contains fish locations (as complex numbers) fishwhere = ZZ(fishpnt); nfish = length(fishwhere); % distances(i,j) = position of shark i - position of fish j if (nfish>0 & nsharks>0), distances = sharkwhere*ones(1,nfish) - ones(nsharks,1)*conj(fishwhere'); else distances = []; end % compute force = sum( distance./abs(distance).^2) distantfishfear = FISHREPEL*(sum(1 ./ distances))'; force(fishpnt) = force(fishpnt) + distantfishfear; % add in global current force = force + Current(ZZ); % discretize force into (1=R, 2=U, 3=L, 4=D, later 0 = no move) intforce = round(angle(force)*(2/pi)); intforce = intforce + 4*(intforce < 0); fishdir(2:d+1,2:d+1)=(intforce+1) .* fish( 2:d+1, 2:d+1 ); % if (dbug == 1), disp('got fish direction'), keyboard, end