Measuring distance between centroid and perimeter points

5 vues (au cours des 30 derniers jours)
ISABELLE GUNDRUM
ISABELLE GUNDRUM le 8 Mar 2022
Réponse apportée : KSSV le 8 Mar 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!

Réponses (1)

KSSV
KSSV le 8 Mar 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.

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by