The following code you added to my original function is unnecessary, since the formula that computes xp and yp automatically takes care of these cases:
% Test for the case where a polygon rib is
% either horizontal or vertical. From Eric Schmitz
id = find(diff(xv)==0);
xp(id)=xv(id);
clear id
id = find(diff(yv)==0);
yp(id)=yv(id);
The only case we should guard against is a case when BOTH A (-diff(yv)) and B (diff(xv)) are identically zero at some points. It effectively means that the input for polygon verices includes duplicate points, i.e. some ribs have zero length and no projection is possible. This case should be flagged out and the function should return an error.
Hi, I have been trying to create a function similar to this one... if I were to have a random polygon but always have as an input the x,y coordinates of the vertices's and and the x,y coordinate of a point. can I use this function to determine the minimum distance of the point to the polygon, and if I can should express the inputs in what way... ?? nice function
This function is as bloated and confusing as the above description. There is just too much going on. An example of use would really help, perhaps included in a published HTML page. I really doubt that anyone can use the file as it is.
I added the suggested test from Eric Schmitz, and also return the point of the polygon closest to the point. It is available here:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=19398&objectType=file