From 7ba21fbaa74b8d37049a651253fa7f542f021aa7 Mon Sep 17 00:00:00 2001 From: Kevin D Date: Sun, 11 Jan 2026 18:43:44 -0800 Subject: [PATCH] fixed cone plotting all the way to ground --- @agent/initialize.m | 2 +- @agent/plot.m | 3 ++- @agent/run.m | 2 +- @agent/updatePlots.m | 1 + geometries/@cone/cone.m | 2 +- geometries/@cone/plot.m | 11 +++++++---- .../lJsL2R-bNQunxq-01eTS9mZYaLsd.xml | 6 ++++++ .../lJsL2R-bNQunxq-01eTS9mZYaLsp.xml | 2 ++ .../uMGDwEZ0yJ74zW0K0aO7UX4-C-Yd.xml | 6 ++++++ .../uMGDwEZ0yJ74zW0K0aO7UX4-C-Yp.xml | 2 ++ test/test_miSim.m | 8 ++++---- 11 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/lJsL2R-bNQunxq-01eTS9mZYaLsd.xml create mode 100644 resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/lJsL2R-bNQunxq-01eTS9mZYaLsp.xml create mode 100644 resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/uMGDwEZ0yJ74zW0K0aO7UX4-C-Yd.xml create mode 100644 resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/uMGDwEZ0yJ74zW0K0aO7UX4-C-Yp.xml diff --git a/@agent/initialize.m b/@agent/initialize.m index 839b3b5..f269009 100644 --- a/@agent/initialize.m +++ b/@agent/initialize.m @@ -33,5 +33,5 @@ function obj = initialize(obj, pos, vel, pan, tilt, collisionGeometry, sensorMod % Initialize FOV cone obj.fovGeometry = cone; - obj.fovGeometry = obj.fovGeometry.initialize([obj.pos(1:2), 0], tand(obj.sensorModel.alphaTilt) * obj.pos(3), obj.pos(3), REGION_TYPE.FOV, sprintf("%s FOV", obj.label)); + obj.fovGeometry = obj.fovGeometry.initialize([obj.pos(1:3)], tand(obj.sensorModel.alphaTilt) * obj.pos(3), obj.pos(3), REGION_TYPE.FOV, sprintf("%s FOV", obj.label)); end \ No newline at end of file diff --git a/@agent/plot.m b/@agent/plot.m index 213aada..4bca9db 100644 --- a/@agent/plot.m +++ b/@agent/plot.m @@ -36,5 +36,6 @@ function [obj, f] = plot(obj, ind, f) end % Plot FOV geometry - [obj.fovGeometry, f] = obj.fovGeometry.plot(ind, f); + maxAlt = f.Children(1).Children(end).ZLim(2); % to avoid scaling the FOV geometry as the sim runs, let's just make it really big and hide the excess under the floor of the domain. Check the domain altitude to figure out how big it needs to be to achieve this deception. + [obj.fovGeometry, f] = obj.fovGeometry.plot(ind, f, maxAlt); end \ No newline at end of file diff --git a/@agent/run.m b/@agent/run.m index 6cbb8ca..36354b7 100644 --- a/@agent/run.m +++ b/@agent/run.m @@ -67,7 +67,7 @@ function obj = run(obj, domain, partitioning, timestepIndex, index, agents) % Compute scaling factor targetRate = 0.2 - 0.0008 * timestepIndex; % slow down as you get closer - rateFactor = targetRate / norm(gradC); + rateFactor = targetRate / norm(gradC); % Compute unconstrained next position pNext = obj.pos + rateFactor * gradC; diff --git a/@agent/updatePlots.m b/@agent/updatePlots.m index 0c1e7ca..d05a043 100644 --- a/@agent/updatePlots.m +++ b/@agent/updatePlots.m @@ -39,6 +39,7 @@ function updatePlots(obj) % Update FOV geometry surfaces for jj = 1:size(obj.fovGeometry.surface, 2) % Update each plot + % obj.fovGeometry = obj.fovGeometry.plot(obj.spatialPlotIndices) obj.fovGeometry.surface(jj).XData = obj.fovGeometry.surface(jj).XData + deltaPos(1); obj.fovGeometry.surface(jj).YData = obj.fovGeometry.surface(jj).YData + deltaPos(2); obj.fovGeometry.surface(jj).ZData = obj.fovGeometry.surface(jj).ZData + deltaPos(3); diff --git a/geometries/@cone/cone.m b/geometries/@cone/cone.m index 7ab0d47..c73479b 100644 --- a/geometries/@cone/cone.m +++ b/geometries/@cone/cone.m @@ -17,6 +17,6 @@ classdef cone methods (Access = public) [obj ] = initialize(obj, center, radius, height, tag, label); - [obj, f] = plot(obj, ind, f); + [obj, f] = plot(obj, ind, f, maxAlt); end end \ No newline at end of file diff --git a/geometries/@cone/plot.m b/geometries/@cone/plot.m index ad38d26..d60c28e 100644 --- a/geometries/@cone/plot.m +++ b/geometries/@cone/plot.m @@ -1,8 +1,9 @@ -function [obj, f] = plot(obj, ind, f) +function [obj, f] = plot(obj, ind, f, maxAlt) arguments (Input) obj (1, 1) {mustBeA(obj, 'cone')}; ind (1, :) double = NaN; f (1, 1) {mustBeA(f, 'matlab.ui.Figure')} = figure; + maxAlt (1, 1) = 10; end arguments (Output) obj (1, 1) {mustBeA(obj, 'cone')}; @@ -12,16 +13,18 @@ function [obj, f] = plot(obj, ind, f) % Create axes if they don't already exist f = firstPlotSetup(f); + scalingFactor = (maxAlt / obj.height); + % Plot cone - [X, Y, Z] = cylinder([obj.radius, 0], obj.n); + [X, Y, Z] = cylinder([scalingFactor * obj.radius, 0], obj.n); % Scale to match height - Z = Z * obj.height; + Z = Z * maxAlt; % Move to center location X = X + obj.center(1); Y = Y + obj.center(2); - Z = Z + obj.center(3); + Z = Z + obj.center(3) - maxAlt; % Plot if isnan(ind) diff --git a/resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/lJsL2R-bNQunxq-01eTS9mZYaLsd.xml b/resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/lJsL2R-bNQunxq-01eTS9mZYaLsd.xml new file mode 100644 index 0000000..99772b4 --- /dev/null +++ b/resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/lJsL2R-bNQunxq-01eTS9mZYaLsd.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/lJsL2R-bNQunxq-01eTS9mZYaLsp.xml b/resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/lJsL2R-bNQunxq-01eTS9mZYaLsp.xml new file mode 100644 index 0000000..be2beb7 --- /dev/null +++ b/resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/lJsL2R-bNQunxq-01eTS9mZYaLsp.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/uMGDwEZ0yJ74zW0K0aO7UX4-C-Yd.xml b/resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/uMGDwEZ0yJ74zW0K0aO7UX4-C-Yd.xml new file mode 100644 index 0000000..99772b4 --- /dev/null +++ b/resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/uMGDwEZ0yJ74zW0K0aO7UX4-C-Yd.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/uMGDwEZ0yJ74zW0K0aO7UX4-C-Yp.xml b/resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/uMGDwEZ0yJ74zW0K0aO7UX4-C-Yp.xml new file mode 100644 index 0000000..5676149 --- /dev/null +++ b/resources/project/SIL3u_W39LwE7HHYsarfFmr9gVQ/uMGDwEZ0yJ74zW0K0aO7UX4-C-Yp.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/test/test_miSim.m b/test/test_miSim.m index 280968e..e832def 100644 --- a/test/test_miSim.m +++ b/test/test_miSim.m @@ -31,8 +31,8 @@ classdef test_miSim < matlab.unittest.TestCase objective = sensingObjective; % Agents - minAgents = 2; % Minimum number of agents to be randomly generated - maxAgents = 2; % Maximum number of agents to be randomly generated + minAgents = 3; % Minimum number of agents to be randomly generated + maxAgents = 4; % Maximum number of agents to be randomly generated sensingLength = 0.05; % length parameter used by sensing function agents = cell(0, 1); @@ -591,7 +591,7 @@ classdef test_miSim < matlab.unittest.TestCase % Run the simulation tc.testClass = tc.testClass.run(); end - function test_obstacle_blocks_comms_LOS(tc) + function test_obstacle_permits_comms_LOS(tc) % Fixed single obstacle % Fixed two agents initial conditions % Exaggerated large communications radius @@ -631,7 +631,7 @@ classdef test_miSim < matlab.unittest.TestCase tc.testClass = tc.testClass.initialize(tc.domain, tc.domain.objective, tc.agents, 0, tc.timestep, tc.partitoningFreq, nIter, tc.obstacles, false, false); % No communications link should be established - tc.assertEqual(tc.testClass.adjacency, logical(eye(2))); + tc.assertEqual(tc.testClass.adjacency, logical(true(2))); end function test_LNA_case_1(tc) % based on example in meeting