Determine if a line segment passes "through" a triangle ... Math gurus,
I apologize because in a previous post I asked how to determine if a line passes through a triangle; and an answer was given. Then, while testing, I came across the scenario where a vertical line “segment” was below the base of the triangle and the answer to my previous question was giving false positives.  This was my own fault because clearly there is a difference between a line and a line segment.
Below is a diagram of what I would like to accomplish.  All the green line segments are considered to be passing "through" the triangle. The red line segments (obviously) do not.

The data I am using has x, y and z values, but for this test, we can assume the triangle and line segment will be coplanar.
The triangle I am using for testing is defined by the points:
vo = (2,2,1) v1 = (7,2,1), v2 = (5,6,1)

and each of my tests cases are using these points:


*

*Line segment outside – no intersection: p0 = (1,4,1) p1 = (3,7,1)

*Intersection at vertex: p0 = (4,6,1) p1 = (8,6,1)

*Intersection through 2 edges: p0 = (4,1,1) p1 = (5,7,1)

*Intersection contains edge: p0 = (1,2,1) p1 = (5,8,1)

*Intersection through 1 vertex and edge: p0 = (5,1,1) p1 = (5,8,1)


Is there some specific formula that will provide a “true” / “false” indication as to whether a line segment passes over the triangle as described above?
I do NOT need to know the point of intersection in the case of a "true" result (but if it is part of determining the result, that would be a bonus).
Thank-you in advance for your help and patience.

Two conditions must be met:


*

*the line of support crosses the triangle. This can be checked by counting the triangle vertices on either side of the line, i.e. 3 LeftOf tests (PQV0, PQV1, PQV2).

*the two endpoints may not both lie on the same side of the lines of support of the sides that are crossed. Takes 2 or 4 more LeftOf tests (among PV0V1, PV1V2, PV2V0, QV0V1, QV1V2, QV2V0; 3 on average).
In the example, two vertices are on the right of PQ and one on the left so that line crosses. It crosses the orange and red sides. Then P and Q aren't on the same side of the orange line.

