Home > matGeom > geom2d > circumCenter.m

circumCenter

PURPOSE ^

CIRCUMCENTER Circumcenter of three points.

SYNOPSIS ^

function varargout = circumCenter(a, b, c)

DESCRIPTION ^

CIRCUMCENTER  Circumcenter of three points.

   CC = circumCenter(P1, P2, P3)

   Example
     A = [10 10]; B = [30 10]; C = [10 20];
     circumCenter(A, B, C)
     ans =
         20    15

     % works also for multiple input points
     circumCenter([A;A;A], [B;B;B], [C;C;C])
     ans =
         20    15
         20    15
         20    15


   See also
     points2d, circles2d, circumCircle, centroid

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = circumCenter(a, b, c)
0002 %CIRCUMCENTER  Circumcenter of three points.
0003 %
0004 %   CC = circumCenter(P1, P2, P3)
0005 %
0006 %   Example
0007 %     A = [10 10]; B = [30 10]; C = [10 20];
0008 %     circumCenter(A, B, C)
0009 %     ans =
0010 %         20    15
0011 %
0012 %     % works also for multiple input points
0013 %     circumCenter([A;A;A], [B;B;B], [C;C;C])
0014 %     ans =
0015 %         20    15
0016 %         20    15
0017 %         20    15
0018 %
0019 %
0020 %   See also
0021 %     points2d, circles2d, circumCircle, centroid
0022 %
0023 
0024 % ------
0025 % Author: David Legland
0026 % e-mail: david.legland@inra.fr
0027 % Created: 2011-12-09,    using Matlab 7.9.0.529 (R2009b)
0028 % Copyright 2011 INRA - Cepia Software Platform.
0029 
0030 % pre-compute some terms
0031 ah = sum(a .^ 2, 2);
0032 bh = sum(b .^ 2, 2);
0033 ch = sum(c .^ 2, 2);
0034 
0035 dab = a - b;
0036 dbc = b - c;
0037 dca = c - a;
0038 
0039 % common denominator
0040 D  = .5 ./ (a(:,1) .* dbc(:,2) + b(:,1) .* dca(:,2) + c(:,1) .* dab(:,2));
0041 
0042 % center coordinates
0043 xc =  (ah .* dbc(:,2) + bh .* dca(:,2) + ch .* dab(:,2) ) .* D;
0044 yc = -(ah .* dbc(:,1) + bh .* dca(:,1) + ch .* dab(:,1) ) .* D;
0045 
0046 if nargout <= 1
0047     varargout = {[xc yc]};
0048 else
0049     varargout = {xc, yc};
0050 end

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