Search code examples
matlabplotviewprojectionmap-projections

How do I calculate the area of a projection created by the command "view"?


How do I calculate the area of a projection? For example, using the following code, I get a projection on the X-Z plane.

[x,y,z]=peaks;
surf(x,y,z);
xlabel('x');ylabel('y');zlabel('z')
view([0,0])

X-Z Plane Projection

I want to be able to determine the area of the projection of any surf plot that I create. Is there a command or function for this?


Solution

  • Short answer

    polyarea(x(1,:),max(z))+polyarea(x(1,:),min(z))
    

    Explanation

    The plot you want to calculate its area is,

    enter image description here

    In area calculation you need only the borders of the projection,

    plot(x(1,:),max(z))
    hold on
    plot(x(1,:),min(z),'r')
    

    and the output is,

    enter image description here

    The total area is the summation of both areas (upper border to x axis and lower border to x axis),

    >> polyarea(x(1,:),max(z))+polyarea(x(1,:),min(z))
    >> 28.5947