Matlab Convhull 错误。没有足够的唯一数据点

Matlab Convhull Error. Not enough unique data point

我在 Matlab 中尝试计算一组由圆内接的数字的凸包时收到此错误。这是代码,我不断得到的错误是:计算凸包时出错。指定的唯一点数不足。

for u = 1:50; 
  for v = 1:50;       
    if sqrt(((u-25)^2)+((v-25)^2)) <= 25
      c = convhull(u,v);
      plot(u(c),v(c),'r-',u,v,'b*')         
    end
  end
end

内接点或圆上的点:

在您的代码中,您将个人积分发送到 convhull。而是首先确定集合中的所有点,然后一次将它们全部发送给函数。这是一个例子。

% create mesh
[u,v] = meshgrid(1:50,1:50);
% get indicies of points within the circle
idx = sqrt((u-25).^2+(v-25).^2) <= 25;
% filter outside points
u = u(idx);
v = v(idx);
% compute convex hull
c = convhull(u,v);
plot(u(c),v(c),'r-',u,v,'b.');

结果


旁注:正式地a singleton set is convex因此它是它自己的凸包。我不确定为什么 MathWorks 在这种情况下决定 return 一个错误。