I'm not sure how well you know the scripting language, but here's how you can calculate the surface area of a mesh. The area of a triangle is equal to half the magnitude of the cross product of two of it's edges. ie. for triangle ABC:
area ABC = 0.5 * | AB X AC |
and then the surface area is just that iterated across the entire mesh. I have a quick estimation for volume as well, but I need to look it up in my scripts.
No, it works on ALL triagles. Read it carefully, I'm not multiplying the height x width, I'm doing a cross-product between two edge vectors, and the definition of the magnitude of a cross product is that it is the area of the parallelogram formed by the two vectors.
Now, on to the volume. There is no guaranteed way to calculate the volume of a polygon mesh, because you can't be sure it's closed & non-intersecting. So this little trick works best (most accurately) on a closed & non-self intersecting mesh. This comes from Duncan B. ("chief scientist" at Alias):
// The method uses the divergence theorem:
// int_{vol} Div(f) dV = int_{surf} Dot(f,n) dS
// To use it to compute volumes set f=(0,0,z), you then have
// Volume = int_{vol} 1 dV = int_{surf} n_z(u,v) du dv
// Where n_z is the "z" component of the normal to the surface at the parameter value (u,v).
// If you only have triangles then the formula reads:
// Volume = sum_{over all triangles} (z0+z1+z2)/3*n_z*A
Anyways, I don't completely get the whole thing about divergance theorem (it's been too long since uni calculus), but here's the nuts & bolts of the algorithm:
iterate through all the triangles summing up:
per triangle: sum+= (area of triangle) * (normal's z component) * (average of z components of the triangle)
It works quite well, surprisingly. If the mesh is closed & continuous, it's best. Otherwise (due to the missing faces) the volume varies if the mesh is positioned differently in the world.
pseudo mel-code: (if each triangle has vertices ABC)
Replies
area ABC = 0.5 * | AB X AC |
and then the surface area is just that iterated across the entire mesh. I have a quick estimation for volume as well, but I need to look it up in my scripts.
(from http://geometryalgorithms.com/Archive/algorithm_0101/
Now, on to the volume. There is no guaranteed way to calculate the volume of a polygon mesh, because you can't be sure it's closed & non-intersecting. So this little trick works best (most accurately) on a closed & non-self intersecting mesh. This comes from Duncan B. ("chief scientist" at Alias):
// The method uses the divergence theorem:
// int_{vol} Div(f) dV = int_{surf} Dot(f,n) dS
// To use it to compute volumes set f=(0,0,z), you then have
// Volume = int_{vol} 1 dV = int_{surf} n_z(u,v) du dv
// Where n_z is the "z" component of the normal to the surface at the parameter value (u,v).
// If you only have triangles then the formula reads:
// Volume = sum_{over all triangles} (z0+z1+z2)/3*n_z*A
Anyways, I don't completely get the whole thing about divergance theorem (it's been too long since uni calculus), but here's the nuts & bolts of the algorithm:
iterate through all the triangles summing up:
per triangle: sum+= (area of triangle) * (normal's z component) * (average of z components of the triangle)
It works quite well, surprisingly. If the mesh is closed & continuous, it's best. Otherwise (due to the missing faces) the volume varies if the mesh is positioned differently in the world.
pseudo mel-code: (if each triangle has vertices ABC)
<font class="small">Code:</font><hr /><pre>
float $volume;
for (each triangle)
{
float $area = 1/2 * cross (vector AB, vector AC);
vector $normal = face normal;
$volume+= $area * $normal.z * (A.z + B.z + C.z)/3
}
</pre><hr />
Now of you can find a Max scripter to write that up you'll be doing well.
No, it works on ALL triagles. Read it carefully,
[/ QUOTE ] 8-P
pwnt