// True if point (x,y) is above line defined by two points
// If line is vertical, "above" is defined as to the right
bool above(double lx1, double ly1, double lx2, double ly2, double x,
double y)
{
return (lx1 != lx2) ? (y > (ly1+(x-lx1)*(ly2-ly1)/(lx2-lx1))) : (x
> lx1);
}
// True if point 1 and point 2 are on the same side of the line
defined by l1 and l2
bool sameSide(double lx1, double ly1, double lx2, double ly2, double
px1, double py1, double px2, double py2)
{
return above(lx1, ly1, lx2, ly2, px1, py1) == above(lx1, ly1, lx2,
ly2, px2, py2);
}
// True if point (x,y) is inside triangle
bool pointInTriangle(double x1, double y1, double x2, double y2,
double x3, double y3, double x, double y)
{
return sameSide(x1,y1,x2,y2,x,y,x3,y3) &&
sameSide(x1,y1,x3,y3,x,y,x2,y2) &&
sameSide(x2,y2,x3,y3,x,y,x1,y1);
}
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.