How to determin whether a point is in triangle or not
Here is a method I develop some years ago... is more efficient since it''s only make 4 mults.
Hi hope it still works
This test if point (p) is inside triangle (abc).
Hi hope it still works
This test if point (p) is inside triangle (abc).
bool pointInside(point2D a, point2D b, point2D c, point2D p){ float sign1, sign2; if ((a.x <= p.x) && (p.x <= c.x)) { sign2 = (p.x - a.x) * (c.y - a.y) - (p.y - a.y) * (c.x - a.x); if ((p.x < b.x) || (b.x == c.x)) sign1 = (p.x - a.x) * (b.y - a.y) - (p.y - a.y) * (b.x - a.x); else sign1 = (p.y - c.y) * (b.x - c.x) - (p.x - c.x) * (b.y - c.y); if (((sign1 >= 0) && (sign2 <= 0)) || ((sign1 <= 0) && (sign2 >= 0))) return true; } return false;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement