Home > matGeom > geom2d > cartesianLine.m

cartesianLine

PURPOSE ^

CARTESIANLINE Create a straight line from cartesian equation coefficients.

SYNOPSIS ^

function line = cartesianLine(varargin)

DESCRIPTION ^

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

   ---------
 Author: David Legland
 e-mail: david.legland@grignon.inra.fr
 created the 25/05/2004.
 Copyright 2010 INRA - Cepia Software Platform.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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@grignon.inra.fr
0014 % created the 25/05/2004.
0015 % Copyright 2010 INRA - Cepia Software Platform.
0016 
0017 
0018 if length(varargin)==1
0019     var = varargin{1};
0020     a = var(:,1);
0021     b = var(:,2);
0022     c = var(:,3);
0023 elseif length(varargin)==3
0024     a = varargin{1};
0025     b = varargin{2};
0026     c = varargin{3};
0027 end
0028 
0029 % normalisation factor
0030 d = a.*a + b.*b;
0031 
0032 x0 = -a.*c./d;
0033 y0 = -b.*c./d;
0034 theta = atan2(-a, b);
0035 dx = cos(theta);
0036 dy = sin(theta);
0037 
0038 line = [x0 y0 dx dy];

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019