STL三角网格模型体积计算

float STLVolume()
{
	float vols = 0;
	for (int i = 0; i < Tmesh->faces.size(); i++)
	{
		vec p1 = Tmesh->vertices[Tmesh->faces[i][0]];
		vec p2 = Tmesh->vertices[Tmesh->faces[i][1]];
		vec p3 = Tmesh->vertices[Tmesh->faces[i][2]];

		float v321 = p3[0] * p2[1] * p1[2];
		float v231 = p2[0] * p3[1] * p1[2];
		float v312 = p3[0] * p1[1] * p2[2];
		float v132 = p1[0] * p3[1] * p2[2];
		float v213 = p2[0] * p1[1] * p3[2];
		float v123 = p1[0] * p2[1] * p3[2];
		vols +=(1.0f / 6.0f)*(-v321 + v231 + v312 - v132 - v213 + v123);
	}
	return abs(vols);
}

参考论文:EFFICIENT FEATURE EXTRACTION FOR 2D/3D OBJECTS IN MESH REPRESENTATION

上一篇:人脸识别代码


下一篇:ProBuilder操作一览表