Home > matGeom > geom2d > createDirectedCircle.m

createDirectedCircle

PURPOSE ^

CREATEDIRECTEDCIRCLE Create a directed circle.

SYNOPSIS ^

function circle = createDirectedCircle(varargin)

DESCRIPTION ^

CREATEDIRECTEDCIRCLE Create a directed circle.

   C = createDirectedCircle(P1, P2, P3);
   Creates a circle going through the given points.
   C is a 1*4 array of the form: [XC YC R INV].
   The last parameter is set to 1 if the points are located in clockwise
   order on the circle.

   C = createDirectedCircle(P1, P2);
   Creates the circle whith center P1 and passing throuh the point P2.

   Works also when input are point arrays the same size, in this case the
   result has as many lines as the point arrays.

   See also:
   circles2d, createCircle

   ---------
   author : David Legland
   INRA - TPV URPOI - BIA IMASTE
   created the 12/01/2005.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function circle = createDirectedCircle(varargin)
0002 %CREATEDIRECTEDCIRCLE Create a directed circle.
0003 %
0004 %   C = createDirectedCircle(P1, P2, P3);
0005 %   Creates a circle going through the given points.
0006 %   C is a 1*4 array of the form: [XC YC R INV].
0007 %   The last parameter is set to 1 if the points are located in clockwise
0008 %   order on the circle.
0009 %
0010 %   C = createDirectedCircle(P1, P2);
0011 %   Creates the circle whith center P1 and passing throuh the point P2.
0012 %
0013 %   Works also when input are point arrays the same size, in this case the
0014 %   result has as many lines as the point arrays.
0015 %
0016 %   See also:
0017 %   circles2d, createCircle
0018 %
0019 %   ---------
0020 %   author : David Legland
0021 %   INRA - TPV URPOI - BIA IMASTE
0022 %   created the 12/01/2005.
0023 %
0024 
0025 if nargin == 2
0026     % inputs are the center and a point on the circle
0027     p1 = varargin{1};
0028     p2 = varargin{2};
0029     x0 = (p1(:,1) + p2(:,1))/2;
0030     y0 = (p1(:,2) + p2(:,2))/2;
0031     r = hypot((p2(:,1)-p1(:,1)), (p2(:,2)-p1(:,2)))/2;
0032     
0033     % circle is direct by default
0034     d = 0;
0035     
0036 elseif nargin == 3
0037     % inputs are three points on the circle
0038     p1 = varargin{1};
0039     p2 = varargin{2};
0040     p3 = varargin{3};
0041 
0042     % compute circle center
0043     line1 = medianLine(p1, p2);
0044     line2 = medianLine(p1, p3);
0045     center = intersectLines(line1, line2);
0046     x0 = center(:, 1); 
0047     y0 = center(:, 2);
0048     
0049     % circle radius
0050     r = hypot((p1(:,1)-x0), (p1(:,2)-y0));
0051     
0052     % compute circle orientation
0053     angle = angle3Points(p1, center, p2) + angle3Points(p2, center, p3);
0054     d = angle>2*pi;
0055 end
0056     
0057         
0058 circle = [x0 y0 r d];

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