/// <summary> /// Calculating the value of the hexahedron /// </summary> /// <returns></returns> public override double GetVolume(Mesh mesh) { //returning value double ret = 0; try { LocationTimeValue[] vert = GetVertices(mesh); //Splitting up the hexahedron into six tetrahedons LocationTimeValue centerPoint = new LocationTimeValue( vert.Average(x => x.X), vert.Average(x => x.Y), vert.Average(x => x.Z) ); CreateFaces(mesh); for (int i = 0; i < 6; i++) { double height = Faces[i].PointDistanceToPlane(centerPoint.ToVector3D()); ret += (1.0 / 3.0) * height * Faces[i].GetArea(); } } catch { ret = 0; } return(ret); }
/// <summary> /// Calculates the volume of the tetrahedon /// </summary> /// <returns></returns> public override double GetVolume(Mesh mesh) { double ret = 0; try { LocationTimeValue[] vert = GetVertices(mesh); LocationTimeValue loc = vert.OrderByDescending(x => Faces[0].PointDistanceToPlane(x.ToVector3D())).First(); double a = Faces[0].PointDistanceToPlane(loc.ToVector3D()); ret = Faces[0].GetArea() * Faces[0].PointDistanceToPlane(loc.ToVector3D()) * (1.0 / 3.0); } catch { ret = double.NaN; } return(ret); }