有没有一种简单的方法来确定一个三角形内一个点?这是2D不是3D。
Is there an easy way to determine if a point inside a triangle? It's 2D not 3D.
在一般情况下,最简单的(和相当最佳)算法检查在其上的边缘点是
In general, the simplest (and quite optimal) algorithm is checking on which side of the half-plane created by the edges the point is.
下面是在GameDev 这话题,包括性能问题,一些高品质的信息。
Here's some high quality info in this topic on GameDev, including performance issues.
和这里的一些code,让你开始:
And here's some code to get you started:
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);
}
bool PointInTriangle (fPoint pt, fPoint v1, fPoint v2, fPoint v3)
{
bool b1, b2, b3;
b1 = sign(pt, v1, v2) < 0.0f;
b2 = sign(pt, v2, v3) < 0.0f;
b3 = sign(pt, v3, v1) < 0.0f;
return ((b1 == b2) && (b2 == b3));
}
上一篇:寻找图中的所有周期图中、周期
下一篇:获得一组Java中的幂Java