答案 0 :(得分:1)
您可以改用Polygon.contains(Point)
吗?
答案 1 :(得分:0)
您的问题并不完全清楚,但假设您只想延长this solution以检查n分,我猜您可以这样做:
private static 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);
}
public static boolean[] pointsInTriangle(fPoint[] pt, fPoint v1, fPoint v2, fPoint v3)
{
boolean b1, b2, b3;
boolean[] ret = new boolean[pt.length];
for (int i = 0; i < pt.length; i++)
{
b1 = sign(pt[i], v1, v2) < 0.0f;
b2 = sign(pt[i], v2, v3) < 0.0f;
b3 = sign(pt[i], v3, v1) < 0.0f;
ret[i] = ((b1 == b2) && (b2 == b3));
}
return ret;
}
顺便说一下,这是O(n)。