views:

65

answers:

1

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?

+5  A: 
KennyTM
Does this hold in all cases? How does this work?
thomasfedb
@thomas: Yes. As illustration, imagine the surface z = 4x - 3y + 2... For detail, try asking on http://math.stackexchange.com/.
KennyTM
@KennyTM: How did you draw that?
Merlyn Morgan-Graham
@Merlyn: http://www.geogebra.org/cms/
KennyTM