Mail Archives: djgpp/1997/10/23/09:33:28
In article <C1256524 DOT 002EA05E DOT 00 AT vega DOT ads DOT it>, G DOT DegliEsposti AT ads DOT it
writes
>
>
>
>
>
>Hello everybody.
>
>Andrew Deren wrote:
>>
>> Does anyone know how to detect if two rectangles overlap each other at
>> some point. Let's say we have something like this:
>>
>> typedef struct RECT {
>> int x1, y1, x2, y2;
>> } RECT;
>>
>In many years I have seen it is not possible to solve this problem without
>lots
>of tests, unless you have some special conditions (and usually you have not
>:-)
>
>You have to test for all vertices of A beeing inside B *and* all vertices
>of B
>beeing inside A, otherwise you can have particular cases where it does not
>work.
This maybe going sideways, but, if you use circles instead of rectangles
then all you use is a bit of pythagoras. If you've got a circle with
radius of r1, and a centre at x1,y1, and another of radius r2, with a
centre at x2,y2, then:
(x1-x2) squared
(y1-y2) squared
Add them up the square root, then, if the answer is smaller than r1+r2
then they are colliding, then after that you may want to do a more
accurate test.
Hope this is of some use.
--
Rob Farley
- Raw text -