0

Is there any known approach to compute the intersection rectangle between two rectangles? I mean if the rectangle A is defined by (x1,y2, x2,y2) and B by (x3,y3, x4,y4), how do I compute the coordinates of the intersection rectangle C (x5,y5, x6,y6)?

Thanks.

abenci
  • 8,422
  • 19
  • 69
  • 134
  • It's been asked and answered [before][1]. [1]: http://stackoverflow.com/questions/7610129/simple-collision-detection-android – Alexey Frunze Oct 06 '11 at 14:50

1 Answers1

0

The general problem of intersecting polygons is explained in detail in here: http://davis.wpi.edu/~matt/courses/clipping . Incidentally, one of the best libraries for the task, with bindings for several programming languages, is GPC - the General Polygon Clipper library: http://www.cs.man.ac.uk/~toby/alan/software

Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • I wrote some code in F# for intersecting two rectangles and creating images based on the result. You can check the code on github: https://github.com/htoma/Rectangles – Horia Toma Feb 05 '16 at 09:19