其他分享
首页 > 其他分享> > STL三角网格模型体积计算

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

标签:p2,p3,三角,STL,float,网格,p1,faces,Tmesh
来源: https://blog.csdn.net/weixin_44478077/article/details/116838447