Testing if a line has a point in a triangle

How to check if a line has a point lying inside (and not on the edge) of a triangle. (All in 2D).

Currently, I think I will do this:

  • Define the line and each side of the triangle as Ax + By + C = 0 and get xrange.
  • Check if the line intersects any of the lines of the triangle.
  • If so, check that it is NOT at the end of the line.

Is there a better way to do this?

+3
source share
1 answer
  • replace 3 points with a linear equation. for example, if the line is 4x & minus; 3y + 2 = 0, and triangular vertices - (2, 1), (4, 3), (0, 5), we get the values ​​7, 9 and -13, respectively.

  • , . , . .

    http://www.imgftw.net/img/743059947.png

+7

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


All Articles