필터 지우기
필터 지우기

Distance of a point to the middle of a polygon

조회 수: 4 (최근 30일)
William Sheehan
William Sheehan 2018년 8월 9일
댓글: Image Analyst 2018년 8월 13일
I currently have a oval shaped polygon with 18 points plotted within the area. All were determined using latitudinal and longitudinal coordinates.
I was wondering if there is anyway of either:
a) Reorientating the points so I can subtract the middle of the field coordinates (lat,long). This will mean I can observe the points with respect to their deviation to either the left or right of centre. Ideally getting a relative position of the points. or
b) Calculate the perpendicular distance from the widest points of the field.
Attached above is a picture of the polygonal area and the points inside for which I want to calculate their relative positions.

답변 (2개)

KSSV
KSSV 2018년 8월 9일
x = rand(10,1) ; y = rand(10,1) ;
mx = mean(x) ; my = mean(y) ;
plot(x,y,'.r') ;
hold on
plot(x-mx,y-my,'.b') ;
legend({'original', 'shifted'})
  댓글 수: 1
William Sheehan
William Sheehan 2018년 8월 11일
This would be okay if the oval shape was always perfectly orientated with the latitude and longitude axis. However, this won't be as accurate if the oval is disorientated in relation to the latitudinal and longitudinal axis.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2018년 8월 11일
If you want to do it numerically/digitally instead of analytically, you can easily do this in a few lines of code. Just use poly2mask to make a digital image from your coordinates. Then call regionprops to get the center of the oval. Then use Pythagorean theorem to get the distance from the centroid to all of the other points.
mask = poly2mask(xOval, yOval, rows, columns);
props = regionprops(mask, 'Centroid');
xCentroid = props.Centroid(1);
yCentroid = props.Centroid(2);
% Find distance from centroid to other points.
distances = sqrt((x-xCentroid).^2 + (y-yCentroid).^2)
  댓글 수: 2
William Sheehan
William Sheehan 2018년 8월 13일
Is there a way i can distingush whether or not an individual is specifically to one side?
I.e. if a marker is in the bottom half of the polygon it is negative or if the polygon is in the upper half it is positive? Likewise with the left and right portions of the polygon?
Image Analyst
Image Analyst 2018년 8월 13일
Yes, take the y coordinate of the pixel and see if it is higher or lower than yCentroid. Same for xCentroid.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by