CARTESIANLINE Create a straight line from cartesian equation coefficients. L = cartesianLine(A, B, C); Create a line verifying the Cartesian equation: A*x + B*x + C = 0; See also lines2d, createLine
0001 function line = cartesianLine(varargin) 0002 %CARTESIANLINE Create a straight line from cartesian equation coefficients. 0003 % 0004 % L = cartesianLine(A, B, C); 0005 % Create a line verifying the Cartesian equation: 0006 % A*x + B*x + C = 0; 0007 % 0008 % See also 0009 % lines2d, createLine 0010 0011 % ------ 0012 % Author: David Legland 0013 % E-mail: david.legland@inrae.fr 0014 % Created: 2004-05-25 0015 % Copyright 2004-2024 INRA - Cepia Software Platform 0016 0017 if isscalar(varargin) 0018 var = varargin{1}; 0019 a = var(:,1); 0020 b = var(:,2); 0021 c = var(:,3); 0022 elseif length(varargin)==3 0023 a = varargin{1}; 0024 b = varargin{2}; 0025 c = varargin{3}; 0026 end 0027 0028 % normalisation factor 0029 d = a.*a + b.*b; 0030 0031 x0 = -a.*c./d; 0032 y0 = -b.*c./d; 0033 theta = atan2(-a, b); 0034 dx = cos(theta); 0035 dy = sin(theta); 0036 0037 line = [x0 y0 dx dy];