cleaned up randomly generated obstacle collision code
This commit is contained in:
@@ -25,7 +25,7 @@ classdef test_miSim < matlab.unittest.TestCase
|
|||||||
|
|
||||||
% Agents
|
% Agents
|
||||||
minAgents = 3; % Minimum number of agents to be randomly generated
|
minAgents = 3; % Minimum number of agents to be randomly generated
|
||||||
maxAgents = 9; % Maximum number of agents to be randomly generated
|
maxAgents = 6; % Maximum number of agents to be randomly generated
|
||||||
sensingLength = 0.05; % length parameter used by sensing function
|
sensingLength = 0.05; % length parameter used by sensing function
|
||||||
agents = cell(0, 1);
|
agents = cell(0, 1);
|
||||||
|
|
||||||
@@ -75,20 +75,10 @@ classdef test_miSim < matlab.unittest.TestCase
|
|||||||
tc.obstacles{ii} = rectangularPrism;
|
tc.obstacles{ii} = rectangularPrism;
|
||||||
tc.obstacles{ii} = tc.obstacles{ii}.initializeRandom(REGION_TYPE.OBSTACLE, sprintf("Obstacle %d", ii), tc.minObstacleSize, tc.maxObstacleSize, tc.domain);
|
tc.obstacles{ii} = tc.obstacles{ii}.initializeRandom(REGION_TYPE.OBSTACLE, sprintf("Obstacle %d", ii), tc.minObstacleSize, tc.maxObstacleSize, tc.domain);
|
||||||
|
|
||||||
% Check if the obstacle intersects with any existing
|
% Check if the obstacle collides with an existing obstacle
|
||||||
% obstacles
|
if ~tc.obstacleCollisionCheck(tc.obstacles(1:(ii - 1)), tc.obstacles{ii})
|
||||||
violation = false;
|
badCandidate = false;
|
||||||
for kk = 1:(ii - 1)
|
|
||||||
if geometryIntersects(tc.obstacles{kk}, tc.obstacles{ii})
|
|
||||||
violation = true;
|
|
||||||
break;
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if violation
|
|
||||||
continue;
|
|
||||||
end
|
|
||||||
|
|
||||||
badCandidate = false;
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -215,20 +205,10 @@ classdef test_miSim < matlab.unittest.TestCase
|
|||||||
tc.obstacles{ii} = rectangularPrism;
|
tc.obstacles{ii} = rectangularPrism;
|
||||||
tc.obstacles{ii} = tc.obstacles{ii}.initializeRandom(REGION_TYPE.OBSTACLE, sprintf("Obstacle %d", ii), tc.minObstacleSize, tc.maxObstacleSize, tc.domain);
|
tc.obstacles{ii} = tc.obstacles{ii}.initializeRandom(REGION_TYPE.OBSTACLE, sprintf("Obstacle %d", ii), tc.minObstacleSize, tc.maxObstacleSize, tc.domain);
|
||||||
|
|
||||||
% Check if the obstacle intersects with any existing
|
% Check if the obstacle collides with an existing obstacle
|
||||||
% obstacles
|
if ~tc.obstacleCollisionCheck(tc.obstacles(1:(ii - 1)), tc.obstacles{ii})
|
||||||
violation = false;
|
badCandidate = false;
|
||||||
for kk = 1:(ii - 1)
|
|
||||||
if geometryIntersects(tc.obstacles{kk}, tc.obstacles{ii})
|
|
||||||
violation = true;
|
|
||||||
break;
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if violation
|
|
||||||
continue;
|
|
||||||
end
|
|
||||||
|
|
||||||
badCandidate = false;
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -380,4 +360,16 @@ classdef test_miSim < matlab.unittest.TestCase
|
|||||||
[tc.testClass, f] = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter);
|
[tc.testClass, f] = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, tc.timestep, tc.partitoningFreq, tc.maxIter);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
methods
|
||||||
|
function c = obstacleCollisionCheck(~, obstacles, obstacle)
|
||||||
|
% Check if the obstacle intersects with any other obstacles
|
||||||
|
c = false;
|
||||||
|
for ii = 1:size(obstacles, 1)
|
||||||
|
if geometryIntersects(obstacles{ii}, obstacle)
|
||||||
|
c = true;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user