←Back

Surface Area and Volume of Arbitrary 3D Geometry

Download: area.zip, volume.zip

Surface Area of a Triangle

area of triangle in 3D
Surface Area of a Triangle in 3D

Suppose there is a single triangle V1-V2-V3 in a 3D space. The surface area of this triangle is a half of the parallelogram constructed by V1, V2 and V3.

area of triangle

where a is the length of V1-V2, and b is the length of V1-V3.

So, you can get the area by performing 2 square roots and sine function. But, there is a simpler formula using the cross product of 2 vectors.

cross product of 2 vectors
Cross Product of 2 Vectors

cross product
By definition of cross product, the magnitude of the cross product cross product is equal to the area of parallelogram constructing 2 vectors.
magnitude of cross product

The cross product is decomposed to a sum of 3 bases vectors and it's magnitude is
magnitude of cross product

Therefore, the area of the triangle is a half of the parallelogram's area, which is the magnitude of the cross product.
area of triangle

Surface Area of 3D Geometry

If an arbitrary 3D geomery is triangulated, the surface areas of the geometry is the sum of area of all triangles constructing the geomery.

If a geomery consists of N triangles, the total surface area is;
cross product is determinant

Here is C++ code snippet to compute the surface area of 3D geometry. The input parameters are an array of vertices, an array of indices and the number of indices for the geometry. See more detail in geomUtils.cpp file.


// calculate area of a single triangle
double computeTriangleArea(float v1[3], float v2[3], float v3[3])
{
    float v12[3];           // v2 - v1
    v12[0] = v2[0] - v1[0];
    v12[1] = v2[1] - v1[1];
    v12[2] = v2[2] - v1[2];
    float v13[3];           // v3 - v1
    v13[0] = v3[0] - v1[0];
    v13[1] = v3[1] - v1[1];
    v13[2] = v3[2] - v1[2];

    // v12 * v13 (cross product)
    double cross[3];
    cross[0] = v12[1]*v13[2] - v13[1]*v12[2];
    cross[1] = v12[2]*v13[0] - v13[2]*v12[0];
    cross[2] = v12[0]*v13[1] - v13[0]*v12[1];

    return 0.5 * sqrt(cross[0]*cross[0] + cross[1]*cross[1] + cross[2]*cross[2]);
}

// calculate area of a geometry
double computeArea(float* vertices, unsigned int* indices, int indexCount)
{
    double sum = 0;
    for(int i = 0; i < indexCount; i += 3)
    {
        float* v1 = &vertices[indices[i]  *3];
        float* v2 = &vertices[indices[i+1]*3];
        float* v3 = &vertices[indices[i+2]*3];
        sum += computeTriangleArea(v1, v2, v3);
    }
    return sum;
}

Approximation Error

Since a 3D geometry is represented with a limited number of triangles, there is an approxiamtion error. For example, the exact area of a sphere with its radius 1 is 12.56637061..., but the area of the sphere with only 1,000 triangles is 12.4654 (99.2% of the exact area). The following chart shows the approximation errors while the number of triangles increases. A sphere with 1M triangles is close to the exact area upto 4 decimal places.

Number of TrianglesComputed AreaErrorAccuracy
1,000 tris12.46540.1009599.1966%
5,000 tris12.54390.0224899.8211%
10,000 tris12.55630.0100999.9197%
50,000 tris12.56420.0021899.9826%
100,000 tris12.56530.0010499.9917%
500,000 tris12.56610.0002399.9982%
1,000,000 tris12.56630.0001099.9992%

Download the testing program to calculate the surface area and error for a sphere. You can increase the number of triangles by pressing SPACE key.
Download: area.zip

Volume of Tetrahedron

Tetrahedron
Parallelepiped and Tetrahedron with O-V1-V2-V3

The volume of a parallelogram prism shape (or parallelepiped) is the product of the base area, A and its height, h, same as a cylinder. And, there are 6 equal-volume tetrahedrons inside the parallelogram prism.

Suppose there is a single triangle V1-V2-V3. You can construct a tetrahedron and parallelepiped with these 3 points and an arbitrary point, e.g. the origin, O. The volume of this tetrahedron is defined by:
volume of tetrahedron

By definition of dot product, dot product, the volume can be computed with volume. Or, it can be expressed using a matrix determinant notation as well.
volume of tetrahedron

Volume of 3D Geometry

If an arbitrary 3D geomery with closed surface (no holes) is triangulated, the volume of the geometry is the sum of the volumes of all tetrahedrons constructed by triangles. If a geometry consists of N triangles, the total volume is;
volume of a geometry

unit cube
Note that the volume of each tetrahedron is signed (can be negative). If a triangle normal is facing to the origin, the volume becomes negative. Therefore, the sum of all the volumes can cancel out outside of the geometry.

Let's visualize the volume calculation using a simple geometry. Suppose there is a unit cube positioned from (0,0,-1) to (1,1,-2). The cube consists of toal 6 faces or 12 triangles. The following diagrams shows the volume of each tetrahedron.

The front face are constructed 2 triangles; (0,0,-1)-(1,1,-1)-(0,1,-1) and (0,0,-1)-(1,0,-1)-(1,1,-1). And, the volumes of the tetrahedrons from the origin are:

front face 1
Front Tetrahedron 1
front face 1
front face 2
Front Tetrahedron 2
front face 2

The right-side triangles are defined by (1,1,-1)-(1,0,-1)-(1,1,-2) and (1,0,-1)-(1,0,-2)-(1,1,-2). The volumes of right-side tetrahedrons are:

right face 1
Right Tetrahedron 1
right face 1
right face 2
Right Tetrahedron 2
right face 2

The top triangles are defined by (1,1,-1)-(0,1,-2)-(0,1,-1) and (1,1,-1)-(1,1,-2)-(0,1,-2). The volumes of top-face tetrahedrons are:

top face 1
Top Tetrahedron 1
top face 1
top face 2
Top Tetrahedron 2
top face 2

The back-side triangles are defined by (0,1,-2)-(1,0,-2)-(0,0,-2) and (0,1,-2)-(1,1,-2)-(1,0,-2). The volumes of back-face tetrahedrons are:

back face 1
Back Tetrahedron 1
back face 1
back face 2
Back Tetrahedron 2
back face 2

The left and bottom faces are on the same plane (the height of tetrahedron is 0), so the volumes are 0 for these faces.

Volumes of the tetrahedrons for left and bottom faces are 0

Therefore, the total volume of the cube is the sum of all tetrahedrons:
volume of cube

Example: Surface Area & Volume

example example

Download: volume.zip

This example loads an OBJ model and calculates the surface are and volume of the OBJ model. And, it visualizes the process of the volume calculations one by one. Please see geomUtils.cpp file ho the surface area and volume are computed.

←Back
 
Hide Comments
comments powered by Disqus