答案 0 :(得分:0)
计算x的y的一种方法是在凸包边缘上运行循环。如果位于x的垂直线与边相交,则找到交点的y坐标。最后,输出这些y值的最大值。一些带注释的代码:
vx = [3 7 4 8 5 9 2 6 5 3]; % test data
vy = [2 4 1 3 2 5 2 6 5 4]; % test data
cvx = convhull(vx, vy);
X = vx(cvx); Y = vy(cvx); % boundary of convex hull
x = 4.2; % test point
y = min(vy); % y starts at minimal value of all y-coords
for (i=1:numel(cvx)-1)
if sign(X(i)-x) ~= sign(X(i+1)-x) % if x is between X(i) and X(i+1)
yc = Y(i+1)*(X(i)-x)/(X(i)-X(i+1)) + Y(i)*(x-X(i+1))/(X(i)-X(i+1));
y = max(y, yc); % compare to linear interpolant yc, take larger
end
end
hold on
plot(vx, vy, 'o')
plot(X, Y)
plot(x, y, 'r*')
hold off
输出: