matlab中提供了判断一个点是否在多边形内部的函数inpolygon,但是这个函数存在与polyarea类似的问题,即要求定义多边形的点必须是沿着多边形连续的,而这在很多时候很难保证。采用类似的思想,我对这个函数进行了适当改造,其健壮性立见提高。
函数 myinpolygon.mfunction flag = myinpolygon(X,Y,xv,yv)
% decide if the points are inside or outside the polygon
% Input:
% X: x-coordinations of the points to be detected
% Y: y-coordinations of the points to be detected
%xv: x-coordinations of the vertex define the polygon
%yv: y-coordinations of the vertex define the polygon
% Output:
%flag=1: inside the polygon
%flag=0: outside the polygon
% Poweed by Xianbao Duan
% Email: xianbao.d@gmail.com
% Website: http://www.52souji.net/
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% log:
% 2012-05-07: Complete
% 2012-05-18: Modify the comments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%