Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Okay, so, I'm not the greatest with geometry (I actually need this for game development), but basically, I need to be able to test whether a vertical (the y-axis is my vertical axis for this) line intersects a triangular plane. I know the 3 vertices of the triangle. The vertical line is actually a line segment, and I know the 2 points that define it. I was thinking that maybe I could test, if the top point on the line is above the plane, and the bottom point is below the plane, then there is an intersection. How would you suggest doing this? I also know that the triangle plane will never be parallel to the y-axis (it never makes a vertical wall), so we don't have to worry about that case. I guess if I could determine the y value on the plane at a given x and z, I could use that, but I don't know how to do that given the 3 vertices that I have. Or maybe I'm thinking about this completely wrong.

share|cite|improve this question
up vote 1 down vote accepted

My first thought is maybe not the best, but it might be computationally feasible.

Since the triangle is not parallel to the y-axis, the plane of the triangle (i.e. if we extend the triangle's sides out... forever) will intersect the line segment's extension. We then do two checks: we check if this point of intersection is actually on the line segment rather than the line (easy check, that's why I mention it first), and then we check if the point is within the triangle itself.

For finding the intersection, I refer you to here.

Is this sufficient?

share|cite|improve this answer
Yeah, that's about what I had in mind. Now as long as I can find the point of intersection properly, and also calculate whether that point is in the triangle (which shouldn't be TOO hard, as I can ignore y-values and use a 2D "projection" of the point and triangle), then that will do just fine. Thanks! – Brandon oubiub Jul 29 '11 at 19:48
@Brandon: Feel free to "upvote" answers that you find helpful (and eventually "accept" the one you like best). Welcome to the forum! – The Chaz 2.0 Jul 29 '11 at 21:01
Yeah, I would upvote the answer, but I guess I need 15 rep to do so. – Brandon oubiub Jul 29 '11 at 21:13
Btw, what I'm actually doing is first testing whether the X and Z coordinates of the vertical line reside within the triangle (I've already done this). Then I will determine at what Y value the plane intersects the line, and then use that to determine whether they intersect. I want the Y-value for collision response. Thanks again for your help! – Brandon oubiub Jul 29 '11 at 23:43

To determine whether the point is in the triangle: The origin is on or inside the triangle with vertices $(x_1,y_1)$, $(x_2,y_2)$, and $(x_3,y_3)$ if and only if there are $a,b,c \ge 0$ such that $a+b+c=1$, $ax_1+bx_2+cx_3 = 0$, and $ay_1+by_2+cy_3 = 0$. Thus, you need only solve the system $$\left(\begin{array}{ccc} 1 & 1 & 1 \\ x_1 & x_2 & x_3 \\ y_1 & y_2 & y_3 \end{array}\right) \left(\begin{array}{c} a \\ b \\ c \end{array}\right) = \left(\begin{array}{c} 1 \\ 0 \\ 0 \end{array}\right)$$ and then check whether $a,b,c \ge 0$.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.