trying to create multiple shapes from points and set different shapes to separate arrays
3 views (last 30 days)
Show older comments
hello all, I was wondering if anyone had any advice as to how to be able to create multiple shapes from given points? Basically, the plot shown comes from an alpha shape, and the points shown are the boundary of the alpha shape, but now I am trying to create shapes within this plot and be able to save the coordinates of the points that make up the shapes into different arrays, different shape = different array. does anyone have any help/guidance with this? I tried using boundary, but this only encompasses the outside points,
i want to be able to retrieve shapes within the interior as well. any help would be really appreciated.
0 Comments
Answers (1)
Subhajyoti
on 8 Dec 2024
It is my understanding that you want to save the coordinates of the points that make up the shapes into different arrays.
You can create multiple shapes from given points and store them in separate arrays, using clustering algorithms to identify clusters of points. Here, in the following implementation, I have used the 'dbscan()' function to cluster the points.
% Sample data: replace this with your actual points
pts1 = [3, 0; 2, 1; 2, -1; 1, 2; 1, -2; 0, 3; 0, -3;
-3, 0; -2, 1; -2, -1; -1, 2; -1, -2];
pts2 = [6, 0; 5, 1; 5, -1; 4, 2; 4, -2; 3, 3; 3, -3; 2, 4; 2, -4; 1, 5; 1, -5; 0, 6; 0, -6;
-6, 0; -5, 1; -5, -1; -4, 2; -4, -2; -3, 3; -3, -3; -2, 4; -2, -4; -1, 5; -1, -5];
points = [pts1; pts2];
% Parameters for DBSCAN
epsilon = 1.5; % Maximum distance between points in a cluster
minPts = 2; % Minimum number of points to form a cluster
% Perform DBSCAN clustering
[idx, ~] = dbscan(points, epsilon, minPts);
% Extract clusters into separate arrays
uniqueClusters = unique(idx);
clusters = cell(length(uniqueClusters) - 1, 1); % Exclude noise cluster (idx = -1)
for i = 1:length(uniqueClusters)
if uniqueClusters(i) ~= -1 % Ignore noise
clusters{i} = points(idx == uniqueClusters(i), :);
end
end
% Display the clusters
% for i = 1:length(clusters)
% fprintf('Cluster %d:\n', i);
% disp(clusters{i});
% end
gscatter(points(:,1), points(:,2), idx);
Refer to the following MathWorks Documentations to know about clustering in MATLAB:
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!