Game Development Reference
In-Depth Information
Line Segment versus Triangle Intersection
Suppose you want to check if a line segment representing a bullet collides with a
particular triangle. The first step to solve this problem is to calculate the plane that
the triangle lies on. Once you have that plane, you can see whether or not the line
segment intersects with it. If they do intersect, you will have a point of intersec-
tion on the plane of the triangle. However, because a plane is infinite, we need to
determine whether this point of intersection is inside or outside a triangle.
If the triangle Δ ABC is expressed in a clockwise winding order, the first step is to
construct a vector from A to B . Then, construct a vector from point A to point P ,
the location that is being tested. If the rotation from vector to is clockwise,
P is on the interior of that side of the triangle. This test can then be repeated for
every other side ( and ), and as long as it is clockwise in every instance, it is
interior of every side, and therefore on the interior of the polygon as a whole. This
is process is shown in Figure 7.8 .
Figure 7.8 Point inside a triangle (a) and outside a triangle (b).
But how do we determine whether the rotation is clockwise or counterclockwise?
Notice how in Figure 7.8(a) , if we were to compute in a right-handed co-
ordinate system, the resultant vector would go into the page. Recall that in a clock-
wise winding order in a right-handed coordinate system, the triangle's normal also
goes into the page. So in this case, the direction of the cross product result is the
same as the triangle's normal vector. If two normalized vectors have a positive dot
product, that means they are facing in roughly the same direction. So if you nor-
Search WWH ::




Custom Search