algorithm - How to determine if a point is in a 2D triangle? -


is there easy way determine if point inside triangle? it's 2d, not 3d.

in general, simplest (and quite optimal) algorithm checking on side of half-plane created edges point is.

here's high quality info in topic on gamedev, including performance issues.

and here's code started:

float sign (fpoint p1, fpoint p2, fpoint p3) {     return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y); }  bool pointintriangle (fpoint pt, fpoint v1, fpoint v2, fpoint v3) {     bool b1, b2, b3;      b1 = sign(pt, v1, v2) < 0.0f;     b2 = sign(pt, v2, v3) < 0.0f;     b3 = sign(pt, v3, v1) < 0.0f;      return ((b1 == b2) && (b2 == b3)); } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -