protected objective from domain edges

This commit is contained in:
2025-10-26 13:30:09 -07:00
parent c61d627f0d
commit 5a9ac0c2d5
12 changed files with 102 additions and 56 deletions

View File

@@ -1,5 +1,5 @@
classdef rectangularPrismConstraint
% Rectangular prism constraint geometry
classdef rectangularPrism
% Rectangular prism geometry
properties (SetAccess = private, GetAccess = public)
tag = REGION_TYPE.INVALID;
label = "";
@@ -19,13 +19,13 @@ classdef rectangularPrismConstraint
methods (Access = public)
function obj = initialize(obj, bounds, tag, label)
arguments (Input)
obj (1, 1) {mustBeA(obj, 'rectangularPrismConstraint')};
obj (1, 1) {mustBeA(obj, 'rectangularPrism')};
bounds (2, 3) double;
tag (1, 1) REGION_TYPE = REGION_TYPE.INVALID;
label (1, 1) string = "";
end
arguments (Output)
obj (1, 1) {mustBeA(obj, 'rectangularPrismConstraint')};
obj (1, 1) {mustBeA(obj, 'rectangularPrism')};
end
obj.tag = tag;
@@ -59,26 +59,62 @@ classdef rectangularPrismConstraint
end
function r = random(obj)
arguments (Input)
obj (1, 1) {mustBeA(obj, 'rectangularPrismConstraint')};
obj (1, 1) {mustBeA(obj, 'rectangularPrism')};
end
arguments (Output)
r (1, 3) double
end
r = (obj.vertices(1, 1:3) + rand(1, 3) .* obj.vertices(8, 1:3) - obj.vertices(1, 1:3))';
end
function d = distance(obj, pos)
arguments (Input)
obj (1, 1) {mustBeA(obj, 'rectangularPrism')};
pos (:, 3) double;
end
arguments (Output)
d (:, 1) double
end
cPos = NaN(1, 3);
for ii = 1:3
if pos(ii) < obj.minCorner(ii)
cPos(ii) = obj.minCorner(ii);
elseif pos(ii) > obj.maxCorner(ii)
cPos(ii) = obj.maxCorner(ii);
else
cPos(ii) = pos(ii);
end
end
d = norm(cPos - pos);
end
function d = interiorDistance(obj, pos)
arguments (Input)
obj (1, 1) {mustBeA(obj, 'rectangularPrism')};
pos (:, 3) double;
end
arguments (Output)
d (:, 1) double
end
% find minimum distance to any face
d = min([pos(1) - obj.minCorner(1), ...
pos(2) - obj.minCorner(2), ...
pos(3) - obj.minCorner(3), ...
obj.maxCorner(1) - pos(1), ...
obj.maxCorner(2) - pos(2), ...
obj.maxCorner(3) - pos(3)]);
end
function c = contains(obj, pos)
arguments (Input)
obj (1, 1) {mustBeA(obj, 'rectangularPrismConstraint')};
obj (1, 1) {mustBeA(obj, 'rectangularPrism')};
pos (:, 3) double;
end
arguments (Output)
c (:, 1) logical
end
c = all(pos >= repmat(obj.minCorner, size(pos, 2), 1), 2) & all(pos <= repmat(obj.maxCorner, size(pos, 2), 1), 2);
c = all(pos >= repmat(obj.minCorner, size(pos, 1), 1), 2) & all(pos <= repmat(obj.maxCorner, size(pos, 1), 1), 2);
end
function f = plotWireframe(obj, f)
arguments (Input)
obj (1, 1) {mustBeA(obj, 'rectangularPrismConstraint')};
obj (1, 1) {mustBeA(obj, 'rectangularPrism')};
f (1, 1) {mustBeA(f, 'matlab.ui.Figure')} = figure;
end
arguments (Output)
@@ -97,7 +133,7 @@ classdef rectangularPrismConstraint
Y = [obj.vertices(edges(:,1),2), obj.vertices(edges(:,2),2)]';
Z = [obj.vertices(edges(:,1),3), obj.vertices(edges(:,2),3)]';
% Plot the boundaries of the constraint geometry
% Plot the boundaries of the geometry
hold(f.CurrentAxes, "on");
plot3(X, Y, Z, '-', 'Color', obj.tag.color, 'LineWidth', 2);
hold(f.CurrentAxes, "off");