Home > functions > common > coordinate > vb_center_sphere.m

vb_center_sphere

PURPOSE ^

Find Center of Sphere from set of points 'X'

SYNOPSIS ^

function [xc ,r] = vb_center_sphere(x)

DESCRIPTION ^

 Find Center of Sphere from set of points 'X'
  [xc ,r] = vb_center_sphere(x)
 --- Input
 x  : N data points in D-dim space (N,D)
 --- Output
 xc : Center of Sphere to fit the data
 r  : Radius of Sphere to fit the data

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    [xc ,r] = vb_center_sphere(x)
0002 % Find Center of Sphere from set of points 'X'
0003 %  [xc ,r] = vb_center_sphere(x)
0004 % --- Input
0005 % x  : N data points in D-dim space (N,D)
0006 % --- Output
0007 % xc : Center of Sphere to fit the data
0008 % r  : Radius of Sphere to fit the data
0009 %
0010 % Copyright (C) 2011, ATR All Rights Reserved.
0011 % License : New BSD License(see VBMEG_LICENSE.txt)
0012 
0013 N    = size(x,1);
0014 xm    = sum(x,1)/N;            % <x>
0015 x    = x - xm(ones(N,1),:);    % X  = x - <x>
0016 xx    = sum(x.^2,2);            % R^2 for x(n)
0017 rr    = sum(xx)/N;            % <R^2>
0018 drr    = xx - rr;                % dRR = R^2 - <R^2>
0019 
0020 C    = (x'* x)/N;            % <X*X'>
0021 B    = (x'* drr)/N;            % <dRR*X>
0022 
0023 xc    = 0.5*(C \ B)';            % = inv(<X*X'>) * <dRR*X>
0024 r   = sqrt(sum(sum( (x - xc(ones(N,1),:)).^2 ))/N);
0025 xc  = xc + xm;
0026

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005