Measuring distance between centroid and perimeter points
조회 수: 2 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (1개)
KSSV
2022년 3월 8일
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!