Reputation: 23
Given the coordinates of each point, how to calculate the area of a three-dimensional surface in MATLAB?
x=-5:1:5;y=-5:1:5;
[xx,yy]=meshgrid(x,y);zz=Z;
figure(1)
mesh(xx,yy,zz)
figure(2)
xb=-5:0.25:5;
yb=-5:0.25:5;
[xxb,yyb]=meshgrid(xb,yb);
zzb=interp2(xx,yy,zz,xxb,yyb,'cubic');
mesh(xxb,yyb,zzb)
above is my code.
the picture is the data of z.
I tried to search for questions alike but I just couldn't find it.
Upvotes: 2
Views: 420
Reputation: 820
1.- alphaShape
does not work for this question because this particular surface is open.
alphaShape
generates 2D or 3D closed POLYGONS.
This is the 1st surface
x=-5:1:5;y=-5:1:5;
[xx,yy]=meshgrid(x,y);
zz=[13.6 -8.2 -14.8 -6.6 1.4 0 -3.8 1.4 13.6 16.8 0
-8.2 -15.8 -7.9 2.2 3.8 0 0.6 7.3 10.1 0 -16.8
-14.8 -7.9 2.5 5.8 2.3 0 2.7 5.1 0 -10.1 -13.7
-6.6 2.2 5.9 3.0 -0.3 0 1.9 0 -5.1 -7.3 -1.4
1.4 3.8 2.3 -0.3 -0.9 0 0 -1.7 -2.7 -0.6 3.8
0 0 0 0 0 0 0 0 0 0 0
-3.8 0.6 2.7 1.7 0 0 0.9 0.3 -2.3 -3.8 -1.4
1.4 7.3 5.1 0 -1.7 0 0.3 -3.1 -5.8 -2.2 6.6
13.6 10.1 0 -5.1 -2.7 0 -2.3 -5.8 -2.5 7.9 14.8
16.8 0 -10.1 -7.3 -0.6 0 -3.8 -2.2 7.9 15.8 8.2
0 16.3 -13.6 -1.4 3.8 0 -1.4 6.6 14.8 8.2 -13.6];
figure(1)
sh1=mesh(xx,yy,zz)
And this is the 2nd surface
figure(2)
xb=-5:0.1:5;
yb=-5:0.1:5;
[xxb,yyb]=meshgrid(xb,yb);
zzb=interp2(xx,yy,zz,xxb,yyb,'cubic');
mesh(xxb,yyb,zzb)
Now try alphaShape
on the 1st surface
P1=[xx(:) yy(:) zz(:)];
shp1 = alphaShape(P1(:,1),P1(:,2),P1(:,3));
figure;
plot(shp1)
axis equal
voila : here is the contraption
and when attempting
A1=area(shp1)
bang :
Error using alphaShape/area
This method is only applicable to 2D alpha shapes.
2.- One has to integrate adding up each flat surface.
The vertexs of each flat surface are available using the handle available from mesh
sh1=mesh(xx,yy,zz)
check the abridged properties
sh1 =
Surface with properties:
EdgeColor: 'flat'
LineStyle: '-'
FaceColor: [1 1 1]
FaceLighting: 'none'
FaceAlpha: 1
XData: [11×11 double]
YData: [11×11 double]
ZData: [11×11 double]
CData: [11×11 double]
click on Show all properties
that shows up right after the abridged properties in Command Window to read all properties
AlignVertexCenters: off
AlphaData: 1
AlphaDataMapping: 'scaled'
AmbientStrength: 0.300000000000000
Annotation: [1×1 matlab.graphics.eventdata.Annotation]
BackFaceLighting: 'reverselit'
BeingDeleted: off
BusyAction: 'queue'
ButtonDownFcn: ''
CData: [11×11 double]
CDataMapping: 'scaled'
CDataMode: 'auto'
...
VertexNormals: [11×11×3 double]
VertexNormalsMode: 'auto'
Visible: on
XData: [11×11 double]
XDataMode: 'manual'
XDataSource: ''
YData: [11×11 double]
YDataMode: 'manual'
YDataSource: ''
ZData: [11×11 double]
ZDataSource: ''
3.- Good News : In The Mathworks File Exchange there is a function called surfarea
, thanks to Sky Santorius, that does exactly the task mentioned in point 2 which is what 石sh asks for.
surfarea
is available in the following link :
Applying surfare to 1st surface
[A1,cell_areas_A1,centroid1]=surfarea(xx,yy,zz);
the resulting surface area is
A1 =
6.783763291711880e+02
and when calculating area of the interpolated 2nd surface
[A2,cell_areas_A2,centroid2]=surfarea(xxb,yyb,zzb);
the resulting surface area is
A2 =
6.504878453848488e+02
Upvotes: 1