检测3D网格中无效三角形的最快方法是什么?我的意思是无效:
我们目前使用这种方法 - 非常慢 - :
if (Area(p1,p2,p3) < 1e-3)
Debug.WriteLine("Invalid triangle found!");
public double Area(Point p1, Point p2, Point p3)
{
double[,] m = new double[3, 3];
m[0, 0] = p1.Y; m[0, 1] = p1.Z; m[0, 2] = 1;
m[1, 0] = p2.Y; m[1, 1] = p2.Z; m[1, 2] = 1;
m[2, 0] = p3.Y; m[2, 1] = p3.Z; m[2, 2] = 1;
double det1 = Matrix.Determinant3(m);
m[0, 0] = p1.Z; m[0, 1] = p1.X; m[0, 2] = 1;
m[1, 0] = p2.Z; m[1, 1] = p2.X; m[1, 2] = 1;
m[2, 0] = p3.Z; m[2, 1] = p3.X; m[2, 2] = 1;
double det2 = Matrix.Determinant3(m);
m[0, 0] = p1.X; m[0, 1] = p1.Y; m[0, 2] = 1;
m[1, 0] = p2.X; m[1, 1] = p2.Y; m[1, 2] = 1;
m[2, 0] = p3.X; m[2, 1] = p3.Y; m[2, 2] = 1;
double det3 = Matrix.Determinant3(m);
return Math.Sqrt(det1 * det1 + det2 * det2 + det3 * det3) / 2;
}
感谢。
答案 0 :(得分:0)
零面积的唯一方法是点是否都是共线的。
尝试以下内容:
p1_p2_slope = (p2.y - p1.y) / (p2.x - p1.x);
p2_p3_slope = (p3.y - p2.y) / (p3.x - p2.x);
if(p1_p2_slope == p2_p3_slope) {
// points are collinear
}
if(p1.x == p2.x && p1.y == p2.y) {
// p1 and p2 overlap
}
if(p1.x == p3.x && p1.y == p3.y) {
// p1 and p3 overlap
}
if(p3.x == p2.x && p3.y == p2.y) {
// p3 and p2 overlap
}
答案 1 :(得分:0)
我认为这样做
abs(dot(sub(b,a), cross(sub(c,b)))) < epsilon
如果你想扩展它,我认为它可以解决这个问题:
abs((b.x - a.x) * (c.y - b.y) + (b.y - a.y) * (b.x - c.x)) < epsilon