I have irregular 3D cartesian coordinates that make up the one eighth of the surface of a sphere. Thanks to Benoit_11 Answer to a previously posed question the surface can now be plotted outside of the MATLAB cftool in a normal command line script
Since this point I have been attempting to calculate the area of the surface using the following code patched together from other answers within the area. The code basically calculates the area from the vertices that produce the surface and then sums them all to produce an area.
surface = [ansx1,ansy1,ansz1];
[m,n] = size(zdata1);
area = 0;
for i = 1:m-1
for j = 1:n-1
v0_1 = [xdata1(i,j) ydata1(i,j) zdata1(i,j) ];
v1_1 = [xdata1(i,j+1) ydata1(i,j+1) zdata1(i,j+1) ];
v2_1 = [xdata1(i+1,j) ydata1(i+1,j) zdata1(i+1,j) ];
v3_1 = [xdata1(i+1,j+1) ydata1(i+1,j+1) zdata1(i+1,j+1)];
a_1= v1_1 - v0_1;
b_1 = v2_1 - v0_1;
c_1 = v3_1 - v0_1;
A_1 = 1/2*(norm(cross(a_1, c_1)) + norm(cross(b_1, c_1)));
area = area + A_1;
end
end
fprintf('\nTotal area is: %f\n\n', area);`
However the issue I am having is that the calculated surface over estimates the possible surface. This is due to the removal of NaN from the original matrix and their replacement with 0 this results in the figure 1. Figure 2 provides the only area I would like to calculate
Does anybody have a way of ignoring the zeros within the code provided to calculate the surface area of the data that generates Figure 1?
Thanks in advance