如果分段交叉,我一生都无法弄清楚如何让它返回 true。任何帮助将不胜感激。
bool doCross(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
bool cross = true;
double denom, uA, uB;
denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
if(denom == 0)
{
cross = false;
}
else
{
uA = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3) / denom;
uB = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3) / denom;
}
if (abs(0 < uA) && abs(uA < 1) && abs(0 < uB) && abs(uB < 1))
{
cross = true;
}
else
{
cross = false;
}
return cross;
}