- Find the mean of the points, C. This will be center of circle.
- Find the distance between C and each point.
- Get the maximum of the distance. This will be Radius R.
Approximate dots area by circle and define its radius
4 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
KSSV
2021 年 10 月 4 日
% Get circle
th = linspace(0,2*pi) ;
x = C(1)+R*cos(th) ;
y = C(2)+R*sin(th) ;
その他の回答 (1 件)
John D'Errico
2021 年 10 月 4 日
編集済み: John D'Errico
2021 年 10 月 4 日
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)
ANd the centroid is:
[Xc,Yc] = centroid(PS)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Computational Geometry についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!