Home > vbmeg > functions > common > utility > vb_util_distance_of_points.m

vb_util_distance_of_points

PURPOSE ^

return distance of point set

SYNOPSIS ^

function dist = vb_util_distance_of_points(points, mode, center)

DESCRIPTION ^

 return distance of point set
 [usage]
   dist = vb_util_distance_of_points(points, mode, center)
 [input]
   points : <required> [NP x 3] 3-D point set (e.g. Vhead)
     mode : <optional> calculation mode (1 or 2 or 3) [1]
          :  =1 : <default> calculate average
          :  =2 : minimum value of all distances
          :  =3 : maximum value of all distances
          :  =other : <warning> calculate average
   center : <optional> coordinates of center point [0 0 0]
 [output]
     dist : calculated distance
 [note]
 
 [history]
   2007-06-14 (Sako) rewrite

 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function dist = vb_util_distance_of_points(points, mode, center)
0002 % return distance of point set
0003 % [usage]
0004 %   dist = vb_util_distance_of_points(points, mode, center)
0005 % [input]
0006 %   points : <required> [NP x 3] 3-D point set (e.g. Vhead)
0007 %     mode : <optional> calculation mode (1 or 2 or 3) [1]
0008 %          :  =1 : <default> calculate average
0009 %          :  =2 : minimum value of all distances
0010 %          :  =3 : maximum value of all distances
0011 %          :  =other : <warning> calculate average
0012 %   center : <optional> coordinates of center point [0 0 0]
0013 % [output]
0014 %     dist : calculated distance
0015 % [note]
0016 %
0017 % [history]
0018 %   2007-06-14 (Sako) rewrite
0019 %
0020 % Copyright (C) 2011, ATR All Rights Reserved.
0021 % License : New BSD License(see VBMEG_LICENSE.txt)
0022 
0023 % --- CHECK ARGUMENTS --- %
0024 if ~exist('points', 'var') points = []; end
0025 if ~exist('mode', 'var') mode = []; end
0026 if ~exist('center', 'var') center = []; end
0027 [points, mode, center] = inner_check_arguments(points, mode, center);
0028 
0029 % --- MAIN PROCEDURE --------------------------------------------------------- %
0030 %
0031 points = [points(:,1)-center(1), points(:,2)-center(2), points(:,3)-center(3)];
0032 
0033 switch mode
0034   case  1
0035     dist = ...
0036       sum(sqrt(points(:,1).^2 + points(:,2).^2 + points(:,3).^2))/length(points);
0037     
0038   case  2
0039     dist = ...
0040       min(sqrt(points(:,1).^2 + points(:,2).^2 + points(:,3).^2));
0041     
0042   case  3
0043     dist = ...
0044       max(sqrt(points(:,1).^2 + points(:,2).^2 + points(:,3).^2));
0045     
0046   otherwise
0047     warning('unexpected mode : %d, calculate average for now', mode);
0048     dist = ...
0049       sum(sqrt(points(:,1).^2 + points(:,2).^2 + points(:,3).^2))/length(points);
0050 end
0051 return;
0052 %
0053 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0054 
0055 % --- INNER FUNCTIONS -------------------------------------------------------- %
0056 %
0057 % --- inner_check_arguments()
0058 %
0059 function [points, mode, center] = inner_check_arguments(points, mode, center)
0060 
0061 func_ = 'vb_util_distance_of_points';
0062 
0063 if isempty(points)
0064   error('(%s)points is a required parameter', func_);
0065 end
0066 
0067 if isempty(mode)
0068   mode = 1;
0069 end
0070 
0071 if isempty(center)
0072   center = [0 0 0];
0073 end
0074 return;
0075 %
0076 % --- end of inner_check_arguments()
0077 %
0078 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0079 
0080 %%% END OF FILE %%%

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005