0

The question is as simple as that, but I have been trying to figure out an answer (and searching for it) with 0 results. I mean, given two triangles (in 2D) I want to find just a single point which they may have in common. Of course I have the long solution consisting of looking for intersections in their perimeter. But maybe you could guide me to a faster solution for computing it.

For example, given the first triangle A(0,0) B(0,4) C(4,0) and the second A'(0,0) B'(2,4) C'(2,0) some possible solutions are : P(0,0) or P(1,1) or P(2,2) or P(1,2), ...

Summary: Im looking for a "fast" algorithm that given A, B, C, A', B', C' it outputs a single point P (if it exists) common to both triangles

Any ideas? Thanks

Ediolot
  • 131
  • I will add that is for learning purposes with openGL programming – Ediolot Mar 20 '15 at 18:28
  • I prefer it to be in the interior, but I will accept one on the sides as well – Ediolot Mar 20 '15 at 18:32
  • There is nothing simple about this question, since there are a number of ways two triangles can overlap. The overlapping region may include none of the 6 vertices of the two triangles, so you really do need to resort to a very generic triangle-triangle intersection routine, then pick some arbitrary point in the intersecting region. – Victor Liu Mar 20 '15 at 19:06
  • Is it required for point to be strictly inside the area? If not, i.e. point might be an intersection point itself, then the simplest (and I suppose the fastest) way is to check pairwise intersections of triangles' edges. Obviously, there are six such checks. – user144765 Mar 20 '15 at 20:15
  • Checking intersections was my first approach but I was really wondering if there was a faster way to do it for a computer. As a human that's how I would do it by hand, but the machine is not the same. – Ediolot Mar 20 '15 at 20:24
  • The common area is either a triangle or a quadrilateral. The former is obtained when a vertex of one triangle is positioned on the side of the second. – Narasimham Mar 21 '15 at 03:01

3 Answers3

0

The idea is simple: find a point that is belonging to both triangle.

If there is an overlap, it means that at least one of the vertices of one triangle is inside the other.

To find if a point is in a triangle, you get the line equations for each edge and check for the sign when you insert the point and the third vertex (out of the three vertices) in the line equation. If the sign is the same that means that the point is in the same side. You do the test for all three combination and if you find that all tests result same sign, it means that the point is in the triangle.

To find the solution for your problem just pick any triangle and check if any of the vertices of the other triangle is in the triangle you selected. It is not important which triangle you pick first.

Then do the test with the other triangle (you might find the solution with the first one. I think that you can easily take it from here, if not will provide you the solution.

Moti
  • 2,011
  • 1
  • 15
  • 16
0

This is a harder problem than it might seem.

A Google search for "intersection of two triangles" came up with, among other suggestions, this, which handles both 2D and 3D triangles: https://hal.inria.fr/inria-00072100/file/RR-4488.pdf .

You can append "2D" to the search to restrict your results.

marty cohen
  • 110,916
0

Depending on what kind of triangles you tend to get and how they are distributed, you might get some benefit by constructing a "bounding box" around each triangle, that is, for each triangle draw a rectangle with sides parallel to your coordinate axes so that the rectangle contains the entire triangle but is as small as possible. At least one vertex of the triangle will be at a corner of the rectangle, and the other two vertices will be at corners or on sides of the rectangle.

Two such rectangles overlap only if their $x$ coordinates overlap and their $y$ coordinates also overlap. This can be checked very quickly. If you have a lot of non-overlapping triangles with sufficient separation, you could efficiently eliminate them as candidates for intersection.

This procedure does not help you much if most of your triangles actually do intercept or if you have a lot of long, needle-shaped triangles all tilted approximately $45$ degrees to the right. It is only really useful if the bounding boxes are very likely not to overlap.

David K
  • 111,757