判断点在两条线之间。

int DotMulti(POINT p1, POINT p2)
{
return p1.x * p2.x + p1.y * p2.y;
}


bool IsBetween(POINT ptA, POINT ptB, POINT ptC, POINT ptTest)
{
POINT v0 = { ptB.x - ptA.x, ptB.y - ptA.y };
POINT v1 = { ptC.x - ptA.x, ptC.y - ptA.y };
POINT v2 = { ptTest.x - ptA.x, ptTest.y - ptA.y };
float iTemp11 = DotMulti(v1, v1);
float iTemp20 = DotMulti(v2, v0);
float iTemp10 = DotMulti(v1, v0);
float iTemp21 = DotMulti(v2, v1);
float iTemp00 = DotMulti(v0, v0);
float m = iTemp00 * iTemp11;
float n = iTemp10 * iTemp10;


if (fabs(m - n) == 0)
return false;
float u = iTemp11 * iTemp20 - iTemp10 * iTemp21;
float v = iTemp00 * iTemp21 - iTemp10 * iTemp20;


return (m - n) > 0 ? (u > 0 && v > 0) : (u < 0 && v < 0);
}

你可能感兴趣的:(判断点在两条线之间。)