-1

I have been trying to find an algorithm which computes the intersecting area of two triangles but I failed to find any. Can anybody give a clue how to write this algorithm?

I would like something like:

  double getAreaOfIntersection(Vector2 p1,Vector2 p2, Vector2 p3,Vector2 p4,Vector2 p5,Vector2 p6 )

where pX represents the 2 triangles.

DalekSupreme
  • 1,493
  • 3
  • 19
  • 32

2 Answers2

5

You could first compute the polygon which describes the intersection area by a clipping algorithm, e.g.:

Sutherland-Hodgman algorithm

Then you would compute the area of the resulting convex polygon, which is rather easy, see, e.g., here:

Area of a Convex Polygon

cfh
  • 4,576
  • 1
  • 24
  • 34
2

Determining wether or not a point lies within a given polygon is easy (and even easier for triangles since those are simple polygons). You can use the winding number algorithm (and the crossing number algorithm for simple polygons) which is implemented and well explained here.

Using this you can obtain all the vertices of your intersection polygon:

  • The vertices pX of a triangle that are contained in the other triangle as well
  • The points where the two triangles intersect (see intersection of line segments)

You will need to loop over your edges to find all the intersection points, so this should be quick enough as long as you only want to determine intersections of triangles but i would not suggest to try to find intersections of arbitrary polygons this way.

H W
  • 2,556
  • 3
  • 21
  • 45