Home Technical Talk

Volume and Surface Area

polycounter lvl 18
Offline / Send Message
Wells polycounter lvl 18
is there an easy way in max to determine the surface area and/or volume of a mesh in the scene's units?

Replies

  • Whargoul
    Offline / Send Message
    Whargoul polycounter lvl 18
    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
    Offline / Send Message
    KDR_11k polycounter lvl 18
    That equation only works with triangles that have one 90° angle. You need to calculate the height on all other types of triangles.
  • Whargoul
    Offline / Send Message
    Whargoul polycounter lvl 18
    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.

    Area_eqn4.gifArea_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. smile.gif
  • Wells
    Offline / Send Message
    Wells polycounter lvl 18
    hot damn. thanks a lot! now to figure out how to utilize this info. smile.gif
  • Wells
    Offline / Send Message
    Wells polycounter lvl 18
    okay, i was just told about the Measure button under the Utilities roll out. tells you all that information and more. d'oh!
  • poopinmymouth
    Offline / Send Message
    poopinmymouth polycounter lvl 19
    [ QUOTE ]
    No, it works on ALL triagles. Read it carefully,

    [/ QUOTE ] 8-P

    pwnt
Sign In or Register to comment.