ISPOINTONPOLYLINE Test if a point belongs to a polyline. B = isPointOnPolyline(POINT, POLY) Returns TRUE of the point POINT belong to the polyline defined by the set of points in POLY. B = isPointOnPolyline(POINT, POLY, TOL) Specify the absolute tolerance for testing the distance between the point and the polyline. Example pt1 = [30 20]; pt2 = [30 10]; poly = [10 10;50 10;50 50;10 50]; isPointOnPolyline([pt1;pt2], poly) ans = 0 1 See also points2d, polygons2d ------ Author: David Legland e-mail: david.legland@grignon.inra.fr Created: 2009-06-19, using Matlab 7.7.0.471 (R2008b) Copyright 2009 INRA - Cepia Software Platform.
0001 function res = isPointOnPolyline(point, poly, varargin) 0002 %ISPOINTONPOLYLINE Test if a point belongs to a polyline. 0003 % 0004 % B = isPointOnPolyline(POINT, POLY) 0005 % Returns TRUE of the point POINT belong to the polyline defined by the 0006 % set of points in POLY. 0007 % 0008 % B = isPointOnPolyline(POINT, POLY, TOL) 0009 % Specify the absolute tolerance for testing the distance between the 0010 % point and the polyline. 0011 % 0012 % Example 0013 % pt1 = [30 20]; 0014 % pt2 = [30 10]; 0015 % poly = [10 10;50 10;50 50;10 50]; 0016 % isPointOnPolyline([pt1;pt2], poly) 0017 % ans = 0018 % 0 0019 % 1 0020 % 0021 % See also 0022 % points2d, polygons2d 0023 % 0024 % ------ 0025 % Author: David Legland 0026 % e-mail: david.legland@grignon.inra.fr 0027 % Created: 2009-06-19, using Matlab 7.7.0.471 (R2008b) 0028 % Copyright 2009 INRA - Cepia Software Platform. 0029 0030 0031 % extract computation tolerance 0032 tol = 1e-14; 0033 if ~isempty(varargin) 0034 tol = varargin{1}; 0035 end 0036 0037 % return true if distance is below a given threshold 0038 res = distancePointPolyline(point, poly) < tol;