Overlapping Rectangles Javascript

5.4k views Asked by At

I need to write an function that takes Rectangles and determines the overlapping area in between them. The format in which the array is shown is the following:

["(0,0),(2,2),(2,0),(0,2),(1,0),(1,2),(6,0),(6,2)"]

The first four points define the first rectangle and the second four define the second.

I have been able to split and parseInt the coordinates, but I am having difficulty on how to find the overlapping area. Thank you!

1

There are 1 answers

0
xiix On

If you have the coordinates as numbers, this is more a math question than a JS question.

Check this: https://math.stackexchange.com/questions/99565/simplest-way-to-calculate-the-intersect-area-of-two-rectangles

Good luck!