English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

If we are given the co-ordinates of the circle and the radius, and the co-ordinates of the rectangle, then how can we prove that the circle and rectangle are over lapping?Java code appreciated!thanx

2007-11-14 23:12:59 · 3 answers · asked by the g 1 in Science & Mathematics Mathematics

3 answers

(x0,y0) is the center of the circle, and R its radius.

I've assumed that your rectangle is aligned with the coordinate axis, being its opposite vertices (x1,y1), (x2,y2), x1
If y1<=y0<=y2, there is overlapping if
x1<=x0+R and x2>=x0-R

If x1<=x0<=x2, there is overlapping if
y1<=y0+R and y2>=y0-R

If y0>=y2 and x0>=x2 is overlapping if
(x2-x0)^2+(y2-y0)^2 <= R^2

If y0>=y2 and x0<=x1 is overlapping if
(x1-x0)^2+(y2-y0)^2 <= R^2

If y0<=y1 and x0>=x2 is overlapping if
(x2-x0)^2+(y1-y0)^2 <= R^2

If y0<=y1 and x0<=x1 is overlapping if
(x1-x0)^2+(y1-y0)^2 <= R^2

If none of these 6 conditions is satisfied, there is no overlapping.

2007-11-14 23:40:33 · answer #1 · answered by GusBsAs 6 · 0 0

Well, you could always get a pencil and a piece of graph paper and draw them :)

Otherwise, you have to prove that some point within the circle also lies within the rectangle.

The equation for the circle with centre (Xc, Yc) and radius R is
(x - Xc) ** 2 + (y - Yc) ** 2 == R ** 2
or, if we want to include points within the circle, then we have an inequality
(x - Xc) ** 2 + (y - Yc) ** 2 <= R ** 2

The rectangle is bounded by four straight lines with equations of the form
y = M[n] * x + C[n]
which you can turn into a set of inequalities satisfied by points within the rectangle.

Now all you need is to find some values for x and y which satisfy all the inequalities at the same time .....

Case one: The rectangle is entirely contained within the circle. In this case, all four of the corners of the rectangle must lie within the circle (although even if just one corner lies within the circle, then the two definitely overlap). Test each of the corners in turn to see if they fall within the circle and return true if any one does.

Case two: The circle is entirely contained within the rectangle. In this case, the centre of the circle must lie within the rectangle (but the converse is not generally true: just because the centre lies within the rectangle does not necessarily mean that the whole of the circle lies within the rectangle). Test the centre of the circle to see if it falls within the rectangle and return true if it does.

Case three: The rectangle and the circle overlap, intersecting in at least one point. In this case, there will be a point on one of the lines which satisfies the equations of both that line (including the limits of the rectangle) and the circle. Treat the equation of each line in turn and the circle as a pair of simultaneous equations in x and y, which can be reduced to a quadratic in x or y. If the quadratic is soluble AND one of the solutions is within the limits of the rectangle, then the circle and rectangle overlap, so return true. (Bear in mind the bounds of the rectangle: it's possible that the shapes do not overlap, but one of the lines would intersect the circle if projected).

If none of the above cases apply, then the rectangle and circle do not overlap, so return false.

2007-11-15 11:16:18 · answer #2 · answered by sparky_dy 7 · 0 0

The rectangle is bounded by 4 lines. We can easily obtain the equations for these 4 lines from the given coordinates.

Then we just have to solve 4 systems of equations.
Each system has a pair of equations, one representing the circle and the other one representing 1 of the 4 lines.

Should we come up with at least 2 points of intersection from these 4 systems, that means the circle intersects the rectangle, and therefore they overlap.

2007-11-15 07:38:01 · answer #3 · answered by BB 2 · 0 0

fedest.com, questions and answers