一个基本想法是简单地丢弃您正在绘制的平面上那些不在数据点凸包内的点。您可以将绘图中这些点的值设置为NaN,因为这会阻止它们显示。
我找不到一个内置函数来检查一个点是否在凸包内。所以你的选择是:
如何滥用scatteredInterpolant
%% Your points and plane
% Random points
P = rand(400, 3);
% Random Plane
[X,Y] = ndgrid(linspace(-0.25, 1.25, 100));
Z = 3*X + 0.3*Y - 2;
%% Compute functions that are the x/y/z-identity inside the hull and `NaN` outside.
hull = unique(convhull(P)); % To make the call of scatteredInterpolant more efficient
insideHull = @(dim) scatteredInterpolant(P(hull,1), P(hull,2), P(hull,3), ...
P(hull,dim), 'linear', 'none');
[insideHx, insideHy, insideHz] = deal(insideHull(1), insideHull(2), insideHull(3));
%% Plot the data points P
plot3(P(:,1), P(:,2), P(:,3), 'x');
hold on;
%% Plot the points of the plane, that are inside the convex hull of P
surf(insideHx(X,Y,Z), insideHy(X,Y,Z), insideHz(X,Y,Z));
因此,您将获得凸包内的刻面,而不是整个平面。
其他方法:
您也可以尝试以下方法之一: