internal boundries of 2d shape
5 views (last 30 days)
Show older comments
I have a matrix that forms a near 2 concentric circles. I need to mark the internal and the external boundaries of the 2 plots as the obtained data is scattered and the plot is a scatter plot. I was only able to obtain the external boundries through the function boundary
0 Comments
Answers (1)
Image Analyst
on 10 Apr 2020
Think about it. There is no internal boundary. You can obtain outer boundary through boundary() or convhull(). Like if you wrapped a rubber band around the points. But for the internal one, if you zoom in you can see that if you want you can extend the boundary into the interior of the mass of points. What you might try is this:
You can find the distance of every point from the origin and sort them in order of increasing distance.
distancesFromOrigin = sqrt(x.^2 + y.^2);
[sortedDistances, sortOrder] = sort(distancesFromOrigin, 'ascend');
Take at least 3 of them (like the 3 closest ones) and fit a circle to them using the FAQ: /FAQ#How_can_I_fit_a_circle_to_a_set_of_XY_data?
xClosest = x(sortOrder(1:3)); % Or however many you want to take.
yClosest = y(sortOrder(1:3));
[xc,yc,R,a] = circfit(xClosest, yClosest)
function [xc,yc,R,a] = circfit(x,y)
%CIRCFIT Fits a circle in x,y plane
%
% [XC, YC, R, A] = CIRCFIT(X,Y)
% Result is center point (yc,xc) and radius R. A is an optional
% output describing the circle's equation:
%
% x^2+y^2+a(1)*x+a(2)*y+a(3)=0
% by Bucher izhak 25/oct/1991
n=length(x); xx=x.*x; yy=y.*y; xy=x.*y;
A=[sum(x) sum(y) n;sum(xy) sum(yy) sum(y);sum(xx) sum(xy) sum(x)];
B=[-sum(xx+yy) ; -sum(xx.*y+yy.*y) ; -sum(xx.*x+xy.*y)];
a=A\B;
xc = -.5*a(1);
yc = -.5*a(2);
R = sqrt((a(1)^2+a(2)^2)/4-a(3));
The 3 closest will give you the smallest circle. Taking more may/will give a larger circle.
Another option is to use alpha shapes, like with activecontour() -- see attached demo.
0 Comments
See Also
Categories
Find more on Polar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!