File Exchange

## Surface area

version 1.2.0.0 (2.43 KB) by
Calculate surface area and centroid of a surface or mesh.

6 Downloads

Updated 15 Aug 2017

View License

Syntax:
[totalArea, areas, centroid] = surfarea(x,y,z)
[totalArea, areas, centroid] = surfarea(h), where h is a handle to a Surface object.

surfarea calculates the total surface area as well as returns the areas of each individual cell, along with the area centroid of the surface.
Example: Plot peaks, coloring each cell with its own area.
[x,y,z] = peaks;
[area,cellAreas,centroid] = surfarea(x,y,z);

h = surf(x,y,z,cellAreas); axis image
title(sprintf('Total surface area: %.2f', surfarea(h)));

### Cite As

Sky Sartorius (2021). Surface area (https://www.mathworks.com/matlabcentral/fileexchange/62992-surface-area), MATLAB Central File Exchange. Retrieved .

### Comments and Ratings (4)

Jerry Campbell

I created a simple Cube with sides of 100mm in AutoCad then exported the STL file
I then used the following code to calculate the volume and surface area of the cube.
% Create PDE Model
UnitCubeModel = createpde();
% Import STL file into Geometry of Model
UnitCubeModelGeometry = importGeometry(UnitCubeModel,'Unit Cube 100mm v1.stl');
% Generate Mesh for Model
UnitCubeMesh = generateMesh(UnitCubeModel);
% V for vertices and F for the facets
% allDisplayFaces is backward compatible method of the Geometry Object
[F, V] = UnitCubeModelGeometry.allDisplayFaces();
% Perform cross product across all the Facets and Vertices in the Model
a = V(F(:, 2), :) - V(F(:, 1), :);
b = V(F(:, 3), :) - V(F(:, 1), :);
c = cross(a, b, 2);
% Calculate Surface Area and Volume of Model
modelSurfaceArea = 1/2 * sum(sqrt(sum(c.^2, 2)));
modelVolume = volume(UnitCubeMesh);
% Plot the PDE Model
pdegplot(UnitCubeModel,'FaceLabels','on','FaceAlpha',0.5);

Cye

This is a very impressive program. I've developed a program for generating various 3D forms and have been stymied as to how to calculate the surface area. Moreover, I have a very limited number of bodies (that are not bodies of revolution) for which the surface area is known. This algorithm gave perfect results for those cases. Of course, I'll continue testing it.

Sky Sartorius

Wei Wu,
Disperse (http://www.mathworks.com/matlabcentral/fileexchange/33866-disperse) is needed. My apologies. I have since updated the file such that disperse is no longer required.

Wei Wu

There is the error at the beginning:

"Undefined function or variable 'disperse'.

Error in surfarea (line 35)
[x,y,z] = disperse(varargin);"

##### MATLAB Release Compatibility
Created with R2016a
Compatible with any release
##### Platform Compatibility
Windows macOS Linux
##### Acknowledgements

Inspired by: disperse

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!