Borrar filtros
Borrar filtros

Measuring distance between centroid and perimeter points

1 visualización (últimos 30 días)
ISABELLE GUNDRUM
ISABELLE GUNDRUM el 8 de Mzo. de 2022
Respondida: KSSV el 8 de Mzo. de 2022
My code currently allows me to draw three polygons on an image and then plot the centroid. How do I measure the distance between the centroid and each perimeter point?
Here is my current code:
close all, imshow(I),
for k = 1:3
title(['Polygon # ' int2str(k)]);
h = drawpolygon;
wait(h);
centroid=mean(h.Position);
drawpoint('Position',centroid,'Label','Centroid');
c{k}(1:2) = round([cx cy],0); % unit: pixels
c{k}(3) = round(area(polyin{k}),0)*p2cm; % unit: cm^2
disp(['Centroid of polygon: [' int2str([cx cy]) ']'])
disp(['Area of polygon = ' int2str(c{k}(3)) 'cm^2'])
end
Thanks!

Respuestas (1)

KSSV
KSSV el 8 de Mzo. de 2022
If C is your centroid coordinates and P is your m*2 array of points. Where m is the number of points. Then you can get the distance using:
d = sqrt((C(1)-P(:,1)).^2+(C(2)-P(:,2)).^2) ;
Alo have a look on pdist2.

Productos


Versión

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by