How can I test whether a line has a point that lies within (not on the edge of) a triangle. (All in 2D).
Currently I’m thinking I’ll do this:
- Define the line, and each side of the triangle as Ax+By+C=0, and have an xrange.
- Check if the line intersects any of the lines of the triangle.
- If it does, check that this is NOT at the end of the line.
Is there a better way to do this?
substitute the 3 points into the line’s equation. e.g. if the line is 4x − 3y + 2 = 0, and the triangle’s vertices are (2, 1), (4, 3), (0, 5), we get the values 7, 9 and -13 respectively.
check if all values are of the same sign. If yes, the line does not intersect the triangle. In the above example, the line intersects the triangle.
http://www.imgftw.net/img/743059947.png