Intersection of a Rectangle and a circle

조회 수: 7 (최근 30일)
Pappu Murthy
Pappu Murthy 2015년 9월 3일
댓글: Image Analyst 2015년 9월 3일
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.

답변 (1개)

Image Analyst
Image Analyst 2015년 9월 3일
편집: Image Analyst 2015년 9월 3일
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
Pappu Murthy
Pappu Murthy 2015년 9월 3일
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 2015년 9월 3일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by