简体   繁体   中英

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: 两个三角形与一个小重叠区域相交,一个点 P 在重叠的中心

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.

The Toussaint algorithm is less easy than it seems, and is complete overkill for two triangles. I would use the Sutherland–Hodgman clipping algorithm. It will take three passes over one of the triangles and output from three to six vertices forming a convex polygon.

The average of the vertices will be inside that polygon. You can even compute the centroid of the area by an extension of the shoelace formula. https://en.wikipedia.org/wiki/Centroid#Of_a_polygon

To simplify some computations, you can start by applying a change of basis such that one of the triangles be reduced to the vertices (0, 0), (0, 1), (1, 0), so that the equations of the half-planes are simply x≥0, y≥0, 1-xy≥0. This will make tests and intersections easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM