diff --git a/exercise3/src/SurfaceArea.cpp b/exercise3/src/SurfaceArea.cpp index 49c2c6f..e5e0930 100644 --- a/exercise3/src/SurfaceArea.cpp +++ b/exercise3/src/SurfaceArea.cpp @@ -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;