Home > bioelectromagnetism > elec_ellipse_points.m

elec_ellipse_points

PURPOSE ^

elec_ellipse_points - Generate points on an ellipse

SYNOPSIS ^

function [x,y,z] = ellipse(a,b,c,N)

DESCRIPTION ^

 elec_ellipse_points - Generate points on an ellipse

 Useage: [X,Y,Z] = elec_ellipse_points(a,b,c,N)

           a   X radius
           b   Y radius
           c   Z radius
           N   Number of points to generate

           [X,Y,Z]     cartesian points

 Example:  [x,y,z] = elec_ellipse_points; surf(x,y,z); shading interp

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [x,y,z] = ellipse(a,b,c,N)
0002 
0003 % elec_ellipse_points - Generate points on an ellipse
0004 %
0005 % Useage: [X,Y,Z] = elec_ellipse_points(a,b,c,N)
0006 %
0007 %           a   X radius
0008 %           b   Y radius
0009 %           c   Z radius
0010 %           N   Number of points to generate
0011 %
0012 %           [X,Y,Z]     cartesian points
0013 %
0014 % Example:  [x,y,z] = elec_ellipse_points; surf(x,y,z); shading interp
0015 %
0016 
0017 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0018 
0019 % Licence:  GNU GPL, no implied or express warranties
0020 % History:  08/01 Darren.Weber_at_radiology.ucsf.edu
0021 %
0022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0023 
0024 if ~exist('a','var'), a = 20; end
0025 if ~exist('b','var'), b = 15; end
0026 if ~exist('c','var'), c = 15; end
0027 if ~exist('N','var'), N = 124; end
0028 
0029 theta = linspace(0,2*pi,N);
0030 phi   = linspace(-pi,pi,N)';
0031 
0032 sinphi = sin(phi);
0033 cosphi = cos(phi);
0034 sintheta = sin(theta);
0035 costheta = cos(theta);
0036 invrho = (sinphi*sintheta/a).^2 + (sinphi*costheta/b).^2 + (cosphi*ones(size(theta))/c).^2;
0037 invrho = sqrt(invrho);
0038 
0039 x = sinphi*costheta./invrho;
0040 y = sinphi*sintheta./invrho;
0041 z = cosphi*ones(size(theta))./invrho;
0042 
0043 return

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