# Approximate dots area by circle and define its radius

10 views (last 30 days)
Elena Novoselova on 4 Oct 2021
Edited: John D'Errico on 4 Oct 2021
I have a 2D logical array and two same-size arrays with cell coordinates. I plotted true dots for one of the cases:
plot(ox(logical_array), oy(logical_array), '.', 'MarkerSize', 20) I need to approximate this area with a circle and define its radius. It isn't nessesary that all points are inside the circle (it's even better if any points are outside to balance the border).
I fount this function https://www.mathworks.com/matlabcentral/fileexchange/5557-circle-fit. As I understand, this code doesn't fit for dot-filled area. Is it possible to adopt this function for my example? Or should I use another solution?
Thank you!

KSSV on 4 Oct 2021
1. Find the mean of the points, C. This will be center of circle.
2. Find the distance between C and each point.
3. Get the maximum of the distance. This will be Radius R.
% Get circle
th = linspace(0,2*pi) ;
x = C(1)+R*cos(th) ;
y = C(2)+R*sin(th) ;
Elena Novoselova on 4 Oct 2021
I would like to receive a circle that smooths the boundaries of the area (some points are outside), and not just contains all the points. Anyway, thanks for your solution! I will use it if I don't find another option.

John D'Errico on 4 Oct 2021
Edited: John D'Errico on 4 Oct 2021
You cannot do anything until you decide what you need to do.
You say to need to approximate it with a circle. If the circle were chosen as the smallest circle that contains ALL points, then theat would define a unique circle. But you say the circle need not contain ALL points. And that suddenly make the problem no longer have a solution, because approximate is not a word with solid definition that makes anything unque.
No, circlefit does NOT do what you want. Certaoinly not until you define what it is you want.
I wonder if possibly the desired circle is one that contains the same "area" as do your points. And then that begs the question, what region do the points inhabit? We need to know that, before we can compute an area.
So possibly, just possibly, you want to compute the convex hull of your point set. A convex hull is a well posed operation. It is the smallest convex object (composed of linear segments around the perimeter) that contains all of the points.
Since I lack your data, and all you gave us is a picture of your points, I'll make some up as an example.
X = rand(10,1);
Y = rand(10,1);
H = convhull(X,Y);
PS = polyshape(X(H),Y(H));
plot(X,Y,'o')
hold on
plot(PS)
xlabel X
ylabel Y
grid on Now, the area of that convex region is
areaps = area(PS)
ans = 0.5279
ANd the centroid is:
[Xc,Yc] = centroid(PS)
Xc = 0.5165
Yc = 0.4858
And, what is the radius of a circle that has the same area as we see in areaps? Since this is surely homework, you need to do some thinking. ALl that requires is the formula for the area of a circle, to compute the radius, when the area is given.
Note that the circle that has the same area as a point set will contain SOME of the points, but unless the points are perfectly circular, some will lie inside, and some outside. (Actually, I will concede if the points all fall on a perfectly regular polygon, then the circle with the same area will fall slightly inside the perimeter points, if you want to be picky. :)
Now, can you plot a circle with that given radius, and the given center? I've already done too much of what is probably your homework to do any more.

R2020a

### Community Treasure Hunt

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

Start Hunting!