Find only interior points from set of points
13 次查看(过去 30 天)
显示 更早的评论
I have a collection of interior and exterior points and need to remove all exterior points from the set. The points can be in any order and any shape. The exterior shape does not have to match the interior shape. However, the inner shape NEVER intersects the outer shape. Both shapes share a common "center" point and I have that data. For example, I could have the points like...
t1 = linspace(0,2*pi, 100);
t2 = wrapTo2Pi(t1 + 0.05);
r1 = 5;
r2 = 10;
r3 = 7;
r4 = 12;
x1 = r1*cos(t1);
y1 = r2*sin(t1);
x2 = r3*cos(t2);
y2 = r4*sin(t2);
xGiven = [x1, x2];
yGiven = [y1, y2];
figure()
scatter(xGiven , yGiven);
Assume, that the only information provided is xGiven, and yGiven. No information on how they were constructed is provided.
Here, I only want the points of the interior ring. The common point shared is [0,0] since both shapes are symmetric about that point.
The only toolbox I have access to is the signal processing toolbox.
Any suggestions would be greatly appreciated.
0 个评论
采纳的回答
Image Analyst
2023-4-18
Try this:
% Demo by Image Analyst separate point sets using the convex hull.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 16;
markerSize = 16;
t1 = linspace(0,2*pi, 100);
t2 = wrapTo2Pi(t1 + 0.05);
r1 = 5;
r2 = 10;
r3 = 7;
r4 = 12;
x1 = r1*cos(t1);
y1 = r2*sin(t1);
x2 = r3*cos(t2);
y2 = r4*sin(t2);
xGiven = [x1, x2];
yGiven = [y1, y2];
figure()
subplot(3, 1, 1);
scatter(xGiven , yGiven, 'filled');
xlim([-8, 8]);
title('All Points', 'FontSize', fontSize);
grid on;
% First get exterior points. They are the convex hull.
chIndexes = convhull(xGiven , yGiven);
xExterior = xGiven(chIndexes);
yExterior = yGiven(chIndexes);
% Now get the interior points. They are whatever is not the convex hull
interiorIndexes = setdiff(1:length(xGiven), chIndexes);
xInterior = xGiven(interiorIndexes);
yInterior = yGiven(interiorIndexes);
% Plot red dots for the exterior points
subplot(3, 1, 2);
plot(xExterior, yExterior, 'r.', 'MarkerSize', markerSize);
xlim([-8, 8]);
grid on;
title('Exterior Points', 'FontSize', fontSize);
% Plot magenta dots for the interior points.
subplot(3, 1, 3);
plot(xInterior, yInterior, 'm.', 'MarkerSize', markerSize);
xlim([-8, 8]);
grid on;
title('Interior Points', 'FontSize', fontSize);
2 个评论
Image Analyst
2023-4-18
I was wondering that myself, but I didn't have time to delve into it. I'd have to zoom way in to see if that point is actually not on the convex hull, or if it is, if there is a bug in the function.
更多回答(1 个)
Akira Agata
2023-4-18
The following is an example:
% Sample data
rng('default');
x = rand(100, 1);
y = rand(100, 1);
% Identiry exterior points
k = boundary(x, y);
% Create index
idxExterior = false(size(x));
idxExterior(k) = true;
idxInterior = ~idxExterior;
% Show the result
figure
tiledlayout('flow')
ax1 = nexttile;
scatter(x,y, 'b.')
daspect([1 1 1])
title('All points')
ax2 = nexttile;
scatter(x(idxExterior), y(idxExterior), 'r.')
daspect([1 1 1])
title('Exterior points')
ax3 = nexttile;
scatter(x(idxInterior), y(idxInterior), 'm.')
daspect([1 1 1])
title('Interior points')
linkaxes([ax1, ax2, ax3], 'xy')
2 个评论
Image Analyst
2023-4-18
Looks like with boundary the points don't have to be convex. The "outer" points can go in and out, have protrusions and bays.
help boundary
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bounding Regions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!