在 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;
}
谢谢。