Search code examples
matlabgeometrycomputational-geometrybounding-box

How to fix this error “Index exceeds the number of array elements (57)” while using minboundquad function


Error shown is Error picture

%x = randn(50,1);
%y = randn(50,1);
points=importdata('points1.txt');
x=points(:,1);
y=points(:,2);
[qx,qy] = minboundquad(x,y);
plot(x,y,'ro',qx,qy,'b-') 

The function is working for randomly generated points but not working for my pointset. Can someone please help me solve this? This is the function minboundquad in Matlab

Or Please lead/help me to find a minimum bounding quadrilateral for a given set of points


Solution

  • Modifying these lines in minboundquad.m from

    edges = convhull(x,y);
    

    to

    edges = convhull(x,y,'Simplify',true);
    

    and

    if ( A_i < quadarea)
    

    to

    if (( A_i < quadarea)&& all(abs([qxi qyi]) < 1e15))
    

    resolves the issue.