PDA

View Full Version : Volume and Surface Area


Sectaurs
10-21-2004, 10:13 PM
is there an easy way in max to determine the surface area and/or volume of a mesh in the scene's units?

Whargoul
10-24-2004, 10:59 AM
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.

KDR_11k
10-24-2004, 12:21 PM
That equation only works with triangles that have one 90° angle. You need to calculate the height on all other types of triangles.

Whargoul
10-24-2004, 12:48 PM
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.

http://geometryalgorithms.com/Archive/algorithm_0101/Area_eqn4.gifhttp://geometryalgorithms.com/Archive/algorithm_0101/Area_pic4.gif

(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. /images/graemlins/smile.gif

Sectaurs
10-24-2004, 04:03 PM
hot damn. thanks a lot! now to figure out how to utilize this info. /images/graemlins/smile.gif

Sectaurs
10-25-2004, 06:11 PM
okay, i was just told about the Measure button under the Utilities roll out. tells you all that information and more. d'oh!

poopinmymouth
10-27-2004, 09:49 AM
[ QUOTE ]
No, it works on ALL triagles. Read it carefully,

[/ QUOTE ] 8-P

pwnt