Intersection of a Rectangle and a circle

10 views (last 30 days)
I have a rectangular domain, and this domain contains several non intersecting circles inside. Say 4 random circles in side a rectangle A,B,C,D. Now I divide the rectangle into n by m subdivisions say 10 x 8 or something of that sort. Next, I need to find whether each of the sub division falls completely out side or completely inside the circles, as well as what is the intersection area if a sub division happens to intersect with the circle. Something like I loop through all sub divisions and check each one say 1). if outside then label it OUT, 2). if inside circle label it IN, and 3). if it cuts any of the circles then A where A is area of intersection. Please help.

Answers (1)

Image Analyst
Image Analyst on 3 Sep 2015
Edited: Image Analyst on 3 Sep 2015
A diagram would have been helpful to illustrate. Assuming you have the boundary coordinates of the circles, you can use inpolygon. Or even more simply, just use the Pythagorean Theorem to see if the distance is greater than the radii. You can use a simple for loop to "visit" every element in your 10 by 8 rectangular array and then calculate the distances to all 4 circles, something like
for col = 1 : columns
for row = 1 : rows
distances = sqrt((row - xCenters).^2 + (col - yCenters).^2);
inside = distances < radii;
end
end
Is this homework, because it sounds a lot like it. Well anyway, there's still a little left for you to do so take that and see if that gives you a good start. There are probably fancier, vectorized ways of doing it (like with meshgrid) but this is a simple intuitive method that's probably easier to understand.
  2 Comments
Pappu Murthy
Pappu Murthy on 3 Sep 2015
This part I understood and fairly easy for me to implement. What seems to be complicated for me is how to find the intersection area which is basically area under the arc that lies with in the rectangle and bounded by the rectangle edges (one needs to know the co-ordinates of the intersection points as well). Again doable but not easily anymore. I was just wondering if there are any functions within Matlab that already do such things so that I don't have to invest a lot of time developing the code.
Image Analyst
Image Analyst on 3 Sep 2015
Sure. Are you willing to do it digitally instead of analytically? If so just make up circles in image arrays according to the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F. To get a smooth circle, and several of them, you're going to have to use more than a 10 by 8 array. Try 1000 by 800 to get decent looking circles with smooth boundaries. Then just use the or operator, and() or &, to find out what pixels the rectangle(s) and circle(s) overlap.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!