Known vertices of a rhombus and a rectangle. What is the simplest and most effective way to find the area of ​​their intersection (the coordinates of the vertices of the figure, which simultaneously belongs to the diamond and the rectangle)?
The rhombus and the rectangle always have this orientation, only their sizes and location on the plane change (I hope, I was correctly expressed).

  • one
    What is meant by the intersection area? Need coordinates of the vertices of the figure, which simultaneously belongs to the diamond and the rectangle? - Andrei NOP
  • one
    Yes, we need the coordinates of the peaks - Egor Moroz

2 answers 2

To find the intersection of arbitrary convex polygons, especially if one of them is an o-oriented rectangle, the sequential clipping algorithm ( Sutherland – Hodgman algorithm ) works fine.

You simply select one of the polygons as a cut-off, and then in a cycle, successively “cut off all unnecessary from it” with straight lines containing the sides of the second (cutting) polygon. In your case, the natural solution would be to choose the rectangle as the cutting: the cutting off by horizontal and vertical straight lines is performed in a trivial way.

    The result can be a convex polygon with the number of vertices from 0 to 8. In order not to analyze all possible cases, you can use the general algorithm of intersection of convex polygons O'Rourke from the book Computational Geometry in C.

    There is a link to the source. The result is a sequence of vertices in traversal order.

    If the probability of crossing is small, then you should first check the fact of crossing (for example, using the SAT method separating axes)