ISPOINTINELLIPSE Check if a point is located inside a given ellipse. B = isPointInEllipse(POINT, ELLIPSE) Returns true if point is located inside the given ellipse. B = isPointInEllipse(POINT, ELLIPSE, TOL) Specifies the tolerance value Example: isPointInEllipse([1 0], [0 0 2 1 0]) ans = 1 isPointInEllipse([0 0], [0 0 2 1 0]) ans = 1 isPointInEllipse([1 1], [0 0 2 1 0]) ans = 0 isPointInEllipse([1 1], [0 0 2 1 30]) ans = 1 See also: ellipses2d, isPointInCircle
0001 function b = isPointInEllipse(point, ellipse, varargin) 0002 %ISPOINTINELLIPSE Check if a point is located inside a given ellipse. 0003 % 0004 % B = isPointInEllipse(POINT, ELLIPSE) 0005 % Returns true if point is located inside the given ellipse. 0006 % 0007 % B = isPointInEllipse(POINT, ELLIPSE, TOL) 0008 % Specifies the tolerance value 0009 % 0010 % Example: 0011 % isPointInEllipse([1 0], [0 0 2 1 0]) 0012 % ans = 0013 % 1 0014 % isPointInEllipse([0 0], [0 0 2 1 0]) 0015 % ans = 0016 % 1 0017 % isPointInEllipse([1 1], [0 0 2 1 0]) 0018 % ans = 0019 % 0 0020 % isPointInEllipse([1 1], [0 0 2 1 30]) 0021 % ans = 0022 % 1 0023 % 0024 % See also: 0025 % ellipses2d, isPointInCircle 0026 % 0027 0028 % --------- 0029 % author : David Legland 0030 % INRA - TPV URPOI - BIA IMASTE 0031 % created the 11/03/2011 0032 % 0033 0034 % HISTORY 0035 0036 % extract computation tolerance 0037 tol = 1e-14; 0038 if ~isempty(varargin) 0039 tol = varargin{1}; 0040 end 0041 0042 % compute ellipse to unit circle transform 0043 rot = createRotation(-deg2rad(ellipse(5))); 0044 sca = createScaling(1./ellipse(3:4)); 0045 trans = sca * rot; 0046 0047 % transform points to unit circle basis 0048 pTrans = bsxfun(@minus, point, ellipse(:,1:2)); 0049 pTrans = transformPoint(pTrans, trans); 0050 0051 % test if distance to origin smaller than 1 0052 b = sqrt(sum(power(pTrans, 2), 2)) - 1 <= tol; 0053