Home > bioelectromagnetism > elec_sphere_points.m

elec_sphere_points

PURPOSE ^

elec_sphere_points - Generate points on a hemisphere, radius R

SYNOPSIS ^

function [x,y,z] = elec_sphere_points(Epoints,Rpoints,R)

DESCRIPTION ^

 elec_sphere_points - Generate points on a hemisphere, radius R

 Useage: [X,Y,Z] = elec_sphere_points(Epoints, Rpoints, R)

           Epoints     number of elevations (phi)
           Rpoints     number of points in rotation (theta)
                       for each level of elevation. Works best
                       when a multiple of 4 or 2, asymmetrical 
                       when odd.
           R           sphere radius

           [X,Y,Z]     cartesian points
                       size = (Epoints * Rpoints) - (Rpoints - 1)
   `                   because the vertex point has no rotation.

 Example:  [x,y,z] = elec_sphere_points(10,16,1); plot3(x,y,z,'o');

 Note:     The points are more numerous closer to the vertex.  It
           is tricky to create points with constant arc length
           separation.

           This function cannot create standard 10-20 electrode
           positions.  These are given in spherical coordinates
           in the text files 'elec_10-20*.txt'.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [x,y,z] = elec_sphere_points(Epoints,Rpoints,R)
0002 
0003 % elec_sphere_points - Generate points on a hemisphere, radius R
0004 %
0005 % Useage: [X,Y,Z] = elec_sphere_points(Epoints, Rpoints, R)
0006 %
0007 %           Epoints     number of elevations (phi)
0008 %           Rpoints     number of points in rotation (theta)
0009 %                       for each level of elevation. Works best
0010 %                       when a multiple of 4 or 2, asymmetrical
0011 %                       when odd.
0012 %           R           sphere radius
0013 %
0014 %           [X,Y,Z]     cartesian points
0015 %                       size = (Epoints * Rpoints) - (Rpoints - 1)
0016 %   `                   because the vertex point has no rotation.
0017 %
0018 % Example:  [x,y,z] = elec_sphere_points(10,16,1); plot3(x,y,z,'o');
0019 %
0020 % Note:     The points are more numerous closer to the vertex.  It
0021 %           is tricky to create points with constant arc length
0022 %           separation.
0023 %
0024 %           This function cannot create standard 10-20 electrode
0025 %           positions.  These are given in spherical coordinates
0026 %           in the text files 'elec_10-20*.txt'.
0027 %
0028 
0029 % $Revision: 1.2 $ $Date: 2005/07/12 22:56:12 $
0030 
0031 % Licence:  GNU GPL, no implied or express warranties
0032 % History:  08/01 Darren.Weber_at_radiology.ucsf.edu
0033 %                 It would be nice to decrease number of Rotation
0034 %                 points for every increase in elevation, but it
0035 %                 is tricky to maintain symmetry.  If possible,
0036 %                 this could maintain near constant arc length
0037 %                 between points.
0038 %
0039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0040 
0041 
0042 eegversion = '$Revision: 1.2 $';
0043 fprintf('ELEC_SPHERE_POINTS [v %s]\n',eegversion(11:15));
0044 fprintf('...generating spherical points\n');
0045 tic;
0046 
0047 phi    = linspace(0,pi/2,Epoints);     % elevation, vertex = 0
0048 
0049 theta1 = linspace(0,2*pi,Rpoints+1);   % 360 degree rotation
0050 theta1 = theta1(1:end-1);              % remove 2*pi (== 0)
0051 
0052 thetad = (theta1(2) - theta1(1))/2;    % provide staggered rotation
0053 
0054 n = 0; odd = 1;
0055 for i = 1:length(phi)
0056     
0057     % every 2nd level of elevation, stagger rotation by thetad
0058     if(odd == 1), odd = 0;  theta = theta1;
0059     else,         odd = 1;  theta = theta1 + thetad;
0060     end
0061     
0062     if isequal(phi(i),0),  % vertex point
0063         n = n + 1;  x(n) = 0;  y(n) = 0;  z(n) = R;
0064     elseif(phi(i) < (pi/8)),
0065         for j = 1:length(theta)
0066             
0067             A(1) = x(n);
0068             A(2) = y(n);
0069             A(3) = z(n);
0070             B(1) = R * sin(phi(i)) * cos(theta(j));
0071             B(2) = R * sin(phi(i)) * sin(theta(j));
0072             B(3) = R * cos(phi(i));
0073             
0074             A_len = sqrt ( sum(A.^2) );
0075             B_len = sqrt ( sum(B.^2) );
0076             
0077             angle = acos( dot(A,B) / (A_len * B_len) );
0078             
0079             if and((phi(i) < (pi/16)),(angle>(pi/90))),
0080                 n = n + 1;
0081                 x(n) = B(1); y(n) = B(2); z(n) = B(3);
0082             elseif(angle>(pi/45)),
0083                 n = n + 1;
0084                 x(n) = B(1); y(n) = B(2); z(n) = B(3);
0085             end
0086         end
0087     else
0088         for j = 1:length(theta)
0089             n = n + 1;
0090             x(n) = R * sin(phi(i)) * cos(theta(j));
0091             y(n) = R * sin(phi(i)) * sin(theta(j));
0092             z(n) = R * cos(phi(i));
0093         end
0094     end
0095 end
0096 x = x';
0097 y = y';
0098 z = z';
0099 
0100 t = toc; fprintf('...done (%6.2f sec).\n\n',t);
0101 
0102 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003