MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / computeVolume

Method computeVolume

src/collision/ConvexMesh.cpp:248–264  ·  view source on GitHub ↗

Compute the volume of the convex mesh We use the divergence theorem to compute the volume of the convex mesh using a sum over its faces.

Source from the content-addressed store, hash-verified

246// Compute the volume of the convex mesh
247/// We use the divergence theorem to compute the volume of the convex mesh using a sum over its faces.
248void ConvexMesh::computeVolume() {
249
250 decimal sum = 0.0;
251
252 // For each face of the mesh
253 for (uint32 f=0; f < getNbFaces(); f++) {
254
255 const HalfEdgeStructure::Face& face = mHalfEdgeStructure.getFace(f);
256 const decimal faceArea = computeFaceNormal(f).length() * decimal(0.5);
257 const Vector3 faceNormal = mFacesNormals[f];
258 const Vector3& faceVertex = getVertex(face.faceVertices[0]);
259
260 sum += faceVertex.dot(faceNormal) * faceArea;
261 }
262
263 mVolume = std::abs(sum) / decimal(3.0);
264}

Callers

nothing calls this directly

Calls 2

lengthMethod · 0.45
dotMethod · 0.45

Tested by

no test coverage detected