Fix surface area

This commit is contained in:
hodasemi 2019-01-05 17:46:02 +01:00
parent 3240f005c7
commit ce1042f3b1

View file

@ -52,6 +52,26 @@ struct Triangles {
return points;
}
float calculate_h(OpenMesh::Vec3f& vector, OpenMesh::Vec3f& p) {
float x = vector[0];
float y = vector[1];
float z = vector[2];
float x1 = p[0];
float y1 = p[1];
float z1 = p[2];
float r = - ( (-x*x1 - y*y1 - z*z1) / (x*x + y*y + z*z) );
OpenMesh::Vec3f s_vec(r * vector);
OpenMesh::Vec3f h_vec = s_vec - p;
float h = h_vec.length();
return h;
}
float surface_area() {
float surface_area = 0.0f;
@ -60,24 +80,12 @@ struct Triangles {
OpenMesh::Vec3f p2 = triangle.points[1];
OpenMesh::Vec3f p3 = triangle.points[2];
/*
OpenMesh::Vec3f p12_vec = p1 - p2;
OpenMesh::Vec3f p23_vec = p1 - p3;
3
/ | \
/ |h \
/ | \
1 -------------- 2
g
OpenMesh::Vec3f cross = OpenMesh::cross(p12_vec, p23_vec);
surface area = (g * h) / 2;
*/
OpenMesh::Vec3f g_vec = p1 - p2;
float g = g_vec.length();
float h = 0.0f;
surface_area += (g * h) / 2;
surface_area += cross.length() / 2;
}
return surface_area;