cleaned up obstacle generation
This commit is contained in:
@@ -1,17 +1,43 @@
|
||||
function [obj] = initializeRandom(obj, minDimension, tag, label)
|
||||
function [obj] = initializeRandom(obj, tag, label, minDimension, maxDimension, domain)
|
||||
arguments (Input)
|
||||
obj (1, 1) {mustBeA(obj, 'rectangularPrism')};
|
||||
minDimension (1, 1) double = 10;
|
||||
tag (1, 1) REGION_TYPE = REGION_TYPE.INVALID;
|
||||
label (1, 1) string = "";
|
||||
minDimension (1, 1) double = 10;
|
||||
maxDimension (1, 1) double= 20;
|
||||
domain (1, 1) {mustBeGeometry} = rectangularPrism;
|
||||
end
|
||||
arguments (Output)
|
||||
obj (1, 1) {mustBeA(obj, 'rectangularPrism')};
|
||||
end
|
||||
|
||||
% Produce random bounds
|
||||
L = ceil(minDimension + rand * minDimension);
|
||||
bounds = [zeros(1, 3); L * ones(1, 3)];
|
||||
% Produce random bounds based on region type
|
||||
if tag == REGION_TYPE.DOMAIN
|
||||
% Domain
|
||||
L = ceil(minDimension + rand * (maxDimension - minDimension));
|
||||
bounds = [zeros(1, 3); L * ones(1, 3)];
|
||||
else
|
||||
% Obstacle
|
||||
|
||||
% Produce a corners that are contained in the domain
|
||||
ii = 0;
|
||||
candidateMaxCorner = domain.maxCorner + ones(1, 3);
|
||||
candidateMinCorner = domain.minCorner - ones(1, 3);
|
||||
% Continue until the domain contains the obstacle without crowding the objective
|
||||
while ~domain.contains(candidateMaxCorner) || all(domain.objective.groundPos + domain.objective.protectedRange >= candidateMinCorner(1:2), 2) && all(domain.objective.groundPos - domain.objective.protectedRange <= candidateMaxCorner(1:2), 2)
|
||||
if ii == 0 || ii > 10
|
||||
candidateMinCorner = domain.random();
|
||||
candidateMinCorner(3) = 0; % bind to floor
|
||||
ii = 1;
|
||||
end
|
||||
|
||||
candidateMaxCorner = candidateMinCorner + minDimension + rand(1, 3) * (maxDimension - minDimension);
|
||||
|
||||
ii = ii + 1;
|
||||
end
|
||||
|
||||
bounds = [candidateMinCorner; candidateMaxCorner;];
|
||||
end
|
||||
|
||||
% Regular initialization
|
||||
obj = obj.initialize(bounds, tag, label);
|
||||
|
||||
@@ -28,7 +28,7 @@ classdef rectangularPrism
|
||||
|
||||
methods (Access = public)
|
||||
[obj ] = initialize(obj, bounds, tag, label, objectiveFunction, discretizationStep);
|
||||
[obj ] = initializeRandom(obj, tag, label);
|
||||
[obj ] = initializeRandom(obj, tag, label, minDimension, maxDimension, domain);
|
||||
[r ] = random(obj);
|
||||
[c ] = contains(obj, pos);
|
||||
[d ] = distance(obj, pos);
|
||||
|
||||
Reference in New Issue
Block a user