Find distance between a circle and a polygon?
Show older comments
Hi!
So I currently have a circle with a know radius and center, and a polygon within that circle. I have attached an image below. The circle shares the same center as a best fit circle for that polygon. I need to find the min, max and average distance between the circle and polygon. I'm not sure where to even start, or what functions to use. Any help is appreciated!
Answers (2)
John D'Errico
on 10 Apr 2023
0 votes
This is clearly homework, of some sort, if you NEED to find those speciific parameters. As such, you need to make an effort.
But first, you should define what is the distance to the circle from that polygon. How would you compute it?
Hint, can you work in polar coordinates, around the center of the circle? I hope so. What tools are there in MATLAB to convert to polar coordinates? Note that you cannot just use cart2pol without some transformation. What origin would cart2pol assume?
Having converted to polar coordinates representation, around the center point, now what does the difference tell you between the radius of the circle, and the parameter r at that polar angle?
Could you use the functions min and max now?
How could you compute an average? An average in this case would mean an integral. Trapz should work.
This is as far as I will take you, which is far more then I probably should have done. Sorry. This is your assignment, not ours.
2 Comments
Tram Nguyen
on 10 Apr 2023
John D'Errico
on 11 Apr 2023
- Extract the pixel coordinates for the polygon.
- Subtract the center of the circle from each point on the polygon. This implicitly translates the problem into one where they are both centered at the origin, so (0,0).
- Convert to polar coordinates. cart2pol will do this now. It gives you radius for the polygon, as a function of polar angle.
- The distance from the circle to the polygon, for every node on the polygon, if R is the radius of the circle, and the polar parameter r for the poltgon. So the distance between the circle and the polygon at that angle is abs(R-r). That is a vector expression. The maximum distance is max(abs(R-r)). The minimum distance is min(abs(R-r)).
- The average distance is simply an integral of that computed distance over theta. Use trapz.
Image Analyst
on 11 Apr 2023
boundaries = bwboundaries(mask);
b = boundaries{1};
x = b(:, 2); % Columns.
y = b(:, 1); % Rows.
Then do what John says.
Categories
Find more on Loops and Conditional Statements 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!