How to assign point to multiple circles
古いコメントを表示
Hi,
I have small script to assign points to circles. However, when a point falls into overlapping circles, then I want it to be assigned to the circle with the nearest center. In other words, a point can only be assigned to one circle. That last part is giving me a problem. Otherwise no more than 2 circles can overlap and if a point fall outside all the circles then it is not assigned anything.
Please note that I dont have any packages.
Thoughts ?
% Positions of points
lat = [47.5, 45.5, 46.5, 46.6, 47.8, 45.7, 44]';
lon = [-63.5, -61.5, -62.5, -62.4, -63.6, -61.7, -59.9]';
pts_positions = table(lat, lon);
% Center of circles
lat = [47, 45, 43]';
lon = [-63, -61, -59]';
name = {'A'; 'B'; 'C'};
circles_positions = table(name,lat, lon);
angles = linspace(0, 2*pi, 720);
radius = 2;
% Assign points to circles
for i = 1:height(circles_positions)
j = circles_positions(i, 1);
x = radius * cos(angles) + circles_positions.lon(i);
y = radius * sin(angles) + circles_positions.lat(i);
mask = pts_positions.lat > min(y) & pts_positions.lon < max(y) & ...
pts_positions.lon > min(x) & pts_positions.lon < max(x);
pts_positions.circle_name(mask) = table2cell(j(1,1));
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Exploration and Visualization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
