The intersection area of ​​two triangles or the set of half planes or the area of ​​a convex set of points

I need to calculate the area of ​​the overlap area between two triangles in a 2D plane. Oddly enough, I wrote code for the triangle-circle problem and that works pretty well and reliably, but I have problems with the triangle-triangle problem.

I already first check whether it completely contains the other, or the other contains the first, and also get all the intersection points along the edges. These intersection points (up to 6, like the star of David), in combination with the triangular vertices that are contained in another triangle, are the vertices of the intersection region. These points should form a convex polygon.

The solution I'm looking for is the answer to any of these questions:

  • Given that the set of all known points lies on the convex hull of the set of points, we calculate the area of ​​the convex hull. Please note that they are in random order.
  • Given a set of half-planes, determine the intersecting area. This is equivalent to describing both triangles as the intersection of three half-planes and computing the solution as a direct intersection of this description.

I looked at question 1 by simply collecting all the areas of all possible triangles, and then dividing by the multiplicity in the count, but that seems dumb, and I'm not sure if this is correct. I feel like there is some sort of sweep algorithm that would do the trick. However, the solution should also be relatively numerically reliable.

, 2, , . , .

. , . , , , , . , , .

+3
1

1: ? , , . - , (, , ). , , , .

-

2 . , a*x+b*y+c=0; (x, y), a*x+b*y+c <= 0 (, ) "" . , ( , ). , .

. . ( ), ; (). , "" , , ; , .

. , , ; , , , . ( !)

, . , , , " ", .

, , , .

/, , , , .

+3

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


All Articles