Search code examples
mathcollision-detectioncomputational-geometry

How do you find the center-point of the intersection/overlap between two triangles in 2D?


For context, I am attempting to resolve collision-details in a 3D physics engine. The following is taking place within a 2D projection onto the separating-plane of two convex shapes.

I have two triangles, let's call them A and B. They are stored as a set of 3 points (eg. A1, A2, A3). I already know that these two triangles overlap. How can I determine a point 'P' that is in roughly the center of that overlap?

The best I could think of is trying to find the intersection of the 6 lines, then, depending upon which intersections existed, including any number of points from either of the triangles. The points selected, along with the intersection-points, could then form a polygon, which I could then find the center of. However, I know that this would be a significant amount of computation, and given this is to be used in a real-time context, I would like to find a better method.

Below is an example of what I am referring to: two triangles intersecting with a small region of overlap, and a point P in the center of the overlap


Solution

  • Besides renowned algorithms for finding the intersection of two convex polygons (general terms than triangle) like the Toussaint algorithm (with java implementation and original paper of the method), you can use the algorithm of this paper (A Triangle-Triangle Intersection Algorithm) to find the intersection area between two triangles.

    Now, as the intersection of two convex objects is convex, you can easily compute the centroid of the intersection using this formula based on the vertices of the intersection area that have been obtained from one of the above algorithms.