问题描述
我正在从分散的数据集中填充轮廓或曲面图.
I'm make a filled contour or surface plot from a scattered dataset.
与其他Qs的主要区别在于数据不是凸的.
A major difference from other Qs is that the data are not convex.
[r,th] = meshgrid(10:15,0:180);
[x,y] = deal(r.*sind(th), r.*cosd(th));
z = x.^2+y.^2;
scatter(x(:),y(:),[],z(:),'fill'); axis equal off;
内圈为空.
我用
tri = delaunay(x,y);
trisurf(tri,x,y,z); view(2); axis equal off;
绘制表面图.
但是,正如您所看到的,内部圆是填充的.
However, as you can see, the inner circle is filled.
推荐答案
您将要使用 alphaShape
,您可以用它来限制所得曲面边缘的长度.
Rather than using the Delaunay triangulation which results in the convex hull, you're going to want to use an alphaShape
with which you can impose a limit on the length of the resulting surfaces edges.
您可以指定 Alpha
属性(通过指定第三个输入),它是最大边长的倒数.对于您的示例,我选择的Alpha
为1.
A = alphaShape(x(:), y(:), 1);
然后您可以使用 alphaTriangulation
alphaSurface
对象的a>方法.
You can then get the triangulation out using the alphaTriangulation
method of your alphaSurface
object.
[faces, vertices] = A.alphaTriangulation();
zvalue = sum(vertices.^2, 2);
或者您可以使用alphaShape
对象的plot
方法
Or you can use the plot
method of the alphaShape
object
plot(A, 'FaceColor', 'interp', 'CData', zvalue)
这篇关于根据不规则数据绘制表面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!