fixed comms LOS obstruction by obstacles

This commit is contained in:
2025-12-24 16:00:42 -08:00
parent 14e372ae55
commit 50eaad9504
4 changed files with 135 additions and 43 deletions

View File

@@ -7,26 +7,41 @@ function obj = updateAdjacency(obj)
end
% Initialize assuming only self-connections
A = logical(eye(size(obj.agents, 1)));
A = true(size(obj.agents, 1));
% Check lower triangle off-diagonal connections
for ii = 2:size(A, 1)
for jj = 1:(ii - 1)
if norm(obj.agents{ii}.pos - obj.agents{jj}.pos) <= min([obj.agents{ii}.comRange, obj.agents{jj}.comRange])
% Make sure that obstacles don't obstruct the line
% of sight, breaking the connection
for kk = 1:size(obj.obstacles, 1)
if ~obj.obstacles{kk}.containsLine(obj.agents{ii}.pos, obj.agents{jj}.pos)
A(ii, jj) = true;
end
end
% need extra handling for cases with no obstacles
if isempty(obj.obstacles)
A(ii, jj) = true;
% Check that agents are not out of range
if norm(obj.agents{ii}.pos - obj.agents{jj}.pos) > min([obj.agents{ii}.comRange, obj.agents{jj}.comRange]);
A(ii, jj) = false; % comm range violation
continue;
end
% Check that agents do not have their line of sight obstructed
for kk = 1:size(obj.obstacles, 1)
if obj.obstacles{kk}.containsLine(obj.agents{jj}.pos, obj.agents{ii}.pos)
A(ii, jj) = false;
end
end
% if norm(obj.agents{ii}.pos - obj.agents{jj}.pos) <= min([obj.agents{ii}.comRange, obj.agents{jj}.comRange])
% % Make sure that obstacles don't obstruct the line
% % of sight, breaking the connection
% for kk = 1:size(obj.obstacles, 1)
% if A(ii, jj) && obj.obstacles{kk}.containsLine(obj.agents{ii}.pos, obj.agents{jj}.pos)
% A(ii, jj) = false;
% end
% end
% % need extra handling for cases with no obstacles
% if isempty(obj.obstacles)
% A(ii, jj) = true;
% end
% end
end
end
obj.adjacency = A | A';
obj.adjacency = A & A';
end