Skip to content
Snippets Groups Projects
Commit 4be2a015 authored by Leonardo de Lima Gaspar's avatar Leonardo de Lima Gaspar
Browse files

Upload New File

parent 6fa54a5a
No related branches found
No related tags found
No related merge requests found
function output = getCenterOfMass2D(input)
output = zeros([2, 2]);
inputSize = size(input);
% The 3-element array stores the index of the optimal row, along with
% its center of mass, plus the overall ratio of mass to not-mass.
bestRow = [1, 0, 0];
bestCol = [1, 0, 0];
for i = 1:inputSize(1)
rowCenter = getCenterOfMass1D(input(i, :));
if rowCenter(2) > bestRow(3)
bestRow = [i, rowCenter(1), rowCenter(2)];
end
end
for i = 1:inputSize(2)
colCenter = getCenterOfMass1D(input(:, i));
if colCenter(2) > bestCol(3)
bestCol = [i, colCenter(1), colCenter(2)];
end
end
output(1, :) = [bestRow(1), bestRow(2)];
output(2, :) = [bestCol(1), bestCol(2)];
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment