我在这里是新的,这是我的第一篇文章..我想知道是否有一种方法可以从100个随机点计算所有可能的凸壳..我创建了一个代码这样做的权利,但它给我一个错误convhull和该部分下的所有东西都无法计算..换句话说,我想知道是否有一种方法,我可以使用函数convhull内循环没有得到一个错误..创建多个凸壳MATLAB
这里是代码
hold on
N=100;
Points = zeros(N,2);
for i=1:N
Points(i,1)= rand(1,1)*100;
Points(i,2)= rand(1,1)*100;
end
SortedX = sortrows(Points,1);
NewVertices = SortedX;
X = reshape(SortedX(:,1),2,[]);
X = X(:);
Y = reshape(SortedX(:,2),2,[]);
Y = Y(:);
plot(X,Y,'*');
while length(NewVertices)>=3
NewVertices = NewVertices(NewVertices~=0);
rowsNV = length(NewVertices(:,1));
NewVertices = reshape(NewVertices,rowsNV/2,2);
XNV = reshape(NewVertices(:,1),rowsNV/2,[]);
XNV = XNV(:);
YNV = reshape(NewVertices(:,2),rowsNV/2,[]);
YNV = YNV(:);
K = convhull(XNV,YNV);
plot(XNV(K),YNV(K),'r-');
for i=1:length(K)-1
NewVertices(K(i),1)=0;
NewVertices(K(i),2)=0;
end
end
以下是错误
Error using convhull
Error computing the convex hull. Not
enough unique points specified.
Error in test2 (line 28)
K = convhull(XNV,YNV);
在此先感谢
co2ark5
这里是最终的代码能够正确工程与DAN的帮助
hold on
N=100;
Points = rand(N,2);
SortedX = sortrows(Points,1);
NewVertices = SortedX;
plot(SortedX(:,1),SortedX(:,2),'*');
while length(NewVertices)>=3
X=NewVertices(:,1);
Y=NewVertices(:,2);
K = convhull(X,Y);
plot(X(K),Y(K),'r-');
for i=1:length(K)-1
NewVertices(K(i),1)=0;
NewVertices(K(i),2)=0;
end
NewVertices = NewVertices(any(NewVertices,2),:);
end
请发表您的代码的一小部分相关的和错误的描述,我们可以看到你要去哪里错了。 – wakjah
对于给定的一组点,是不是只有一个独特的凸包?所有可能的凸包是什么意思?也请张贴代码和错误 – Dan
你是对的有一个点的一个凸包,但每次我计算从左点的下一个凸包.. – co2ark5