MATLAB: Does the “polyshape” function deletes the vertices in the input when there are no duplicated points or intersections

MATLABpolyshapewarning

Why does the "polyshape" function deletes the vertices in the input when there are no duplicated points or intersections?
I am receiving the following warning message when I am using the "polyshape" function:
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected
results. Input data has been modified to create a well-defined polyshape.
> In polyshape/checkAndSimplify (line 339)
Why does the function deletes half the total number of vertices in the input when there are no duplicated points or intersections? 

I have checked the points and the order by using fill function. There is no duplicated points or intersections. If you run the attached script (questionScript.m) and zoom in, you can see that each 2 points are very close to each other and "polyshape" function deletes one of the point in each pair.

Is it the case that the function just treats close points as duplicated points? If so, is there a way to set an absolute threshold distance that the function can treat the close points as duplicates?

Best Answer

Please confirm if the "polyshape" function is used in the default way or not. 
If it is used in a default way, it tries to detect and fix intersections, remove collinear points, remove overlapping points, etc.
After the release of MATLAB R2018b, there is a new name/value pair for polyshape(), "KeepCollinearPoints"=true/false, for the keeping the collinear points purpose. By default 'KeepCollinearPoints' is set to false.
If you want to keep the collinear points then you can set 'KeepCollinearPoints' to true.
As of MATLAB R2018a, the reason for the "polyshape" function to delete half the total number of vertices in the input when there are no duplicate points or intersections is most likely as the input vertices contain collinear points.
Regarding the other query, if there is a way to set an absolute threshold distance so that the function can treat the close points as duplicates, currently, there is no such threshold value. 
However, as a workaround, you can call the "polyshape" function with a name/value pair, as follows:
>> p2 = polyshape(points(path,1), points(path,2), 'simplify', false);
This will keep all the input points without simplifying it, as follows:
p2 = 
polyshape with properties:
Vertices: [142×2 double]
NumRegions: 1
NumHoles: 0
You can use the "simplify" function, "p3 = simplify(p2)", later if you need to simplify the input data. Please note that "p3" will be the same as polygon in the script.