Rotary 2d rectangular intersecting points or area

Move forward the previous question . I have two rectangles and they look like this:

struct Rect
{
 NSPoint topLeft; 
 NSPoint topRight; 
 NSPoint bottomLeft; 
 NSPoint bottomRight; 
}

I use something like this to check if rectangles (or collision) intersect. If two rectangles intersect, I want to calculate the intersection area in the first rectangle or the point where the second rectangle intersects with the first rectangle (i.e., the intersection coordinates).

How to calculate intersecting points or an intersection area.

+3
source share
2 answers

You can determine the intersection points by doing the following:

foreach line in rectangle 1: line1
  foreach line in rectangle 2: line2
    find point of intersection for line1, line2

:

http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/

, , , , / . 8 3 ( ).

, , , :)

+2

, , , " ". ( ).

, :

http://www.cs.man.ac.uk/aig/staff/alan/software/

, ( - ). , , , .

, , SO:

?

+2

Source: https://habr.com/ru/post/1759830/


All Articles