g0dspl4y
g0dspl4y

Reputation: 27

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?

Upvotes: 1

Views: 1007

Answers (2)

Hazem
Hazem

Reputation: 380

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

Upvotes: 1

user1004061
user1004061

Reputation: 103

If you want to get the projection area at an arbitrary view angle, you can use the viewmtx function to project the surface onto the viewing plane, and then use boundary and polyarea to extract the boundary and calculate the area. Something like this:

 % draw your surface
 [x,y,z]=peaks;
 surf(x,y,z);
 xlabel('x');ylabel('y');zlabel('z')
 axis equal;
 %extract the viewing angle, and calculate the resulting transformation matrix
 [az,el]=view(gca);
 T= viewmtx(az,el);
 % transform the surface points by this transformation matrix
 pts= [x(:),y(:),z(:),ones(numel(x),1)]';
 tpts= T*pts;
 tpts=(tpts(1:3,:))';
 % now "tpts" has the surface points projected onto the viewing plane
 figure, plot( tpts(:,1), tpts(:,2), 'bo'); axis equal;
 % calculate the border of this region, and calculate its area.
 border = boundary(tpts(:,1), tpts(:,2));
 projectedArea = polyarea(tpts(border,1), tpts(border,2));

This approach is based off of the help for viewmtx.

Upvotes: 0

Related Questions