如何确定一个三角形的一个点? [英] How to determine a point in a triangle?
本文介绍了如何确定一个三角形的一个点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种简单的方法来确定一个三角形内一个点?这是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));
}
这篇关于如何确定一个三角形的一个点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文