Volume returns the volume. NOTE: This only works for closed triangle-based meshes.
()
| 383 | // Volume returns the volume. |
| 384 | // NOTE: This only works for closed triangle-based meshes. |
| 385 | func (g *Geometry) Volume() float32 { |
| 386 | |
| 387 | // If valid, return its value |
| 388 | if g.volumeValid { |
| 389 | return g.volume |
| 390 | } |
| 391 | |
| 392 | // Reset volume |
| 393 | g.volume = 0 |
| 394 | |
| 395 | // Calculate volume of all tetrahedrons |
| 396 | g.ReadFaces(func(vA, vB, vC math32.Vector3) bool { |
| 397 | vA.Sub(&vC) |
| 398 | vB.Sub(&vC) |
| 399 | g.volume += vC.Dot(vA.Cross(&vB)) / 6.0 |
| 400 | return false |
| 401 | }) |
| 402 | g.volumeValid = true |
| 403 | return g.volume |
| 404 | } |
| 405 | |
| 406 | // RotationalInertia returns the rotational inertia tensor, also known as the moment of inertia. |
| 407 | // This assumes constant density of 1 (kg/m^2). |