如何计算命令 "view" 创建的投影面积?

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

如何计算投影的面积?例如,使用以下代码,我得到了 X-Z 平面上的投影。

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

X-Z Plane Projection

我希望能够确定我创建的任何冲浪图的投影区域。有这方面的命令或功能吗?

简答

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

说明

您要计算其面积的地块是,

面积计算只需要投影的边界,

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

输出是,

总面积是两个面积(x轴的上边界和x轴的下边界)的总和,

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

如果想得到任意视角的投影面积,可以使用viewmtx函数将曲面投影到观察平面上,然后使用boundarypolyarea提取边界并计算面积。像这样:

 % 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));

此方法基于 viewmtx 的帮助。