ELLIPSOIDMESH Convert a 3D ellipsoid to face-vertex mesh representation. [V, F] = ellipsoidMesh(ELLI) ELLI is given by: [XC YC ZC A B C PHI THETA PSI], where (XC, YC, ZC) is the ellipsoid center, A, B and C are the half lengths of the ellipsoid main axes, and PHI THETA PSI are Euler angles representing ellipsoid orientation, in degrees. Example % compute mesh of an ellongated ellipsoid elli = [50 50 50 50 30 10 30 20 10]; [v, f] = ellipsoidMesh(elli); figure; hold on; axis equal; axis([0 100 0 100 0 100]); view(3); drawMesh(v, f); See also meshes3d, drawEllipsoid, sphereMesh, equivalentEllipsoid
0001 function varargout = ellipsoidMesh(elli, varargin) 0002 %ELLIPSOIDMESH Convert a 3D ellipsoid to face-vertex mesh representation. 0003 % 0004 % [V, F] = ellipsoidMesh(ELLI) 0005 % ELLI is given by: 0006 % [XC YC ZC A B C PHI THETA PSI], 0007 % where (XC, YC, ZC) is the ellipsoid center, A, B and C are the half 0008 % lengths of the ellipsoid main axes, and PHI THETA PSI are Euler angles 0009 % representing ellipsoid orientation, in degrees. 0010 % 0011 % Example 0012 % % compute mesh of an ellongated ellipsoid 0013 % elli = [50 50 50 50 30 10 30 20 10]; 0014 % [v, f] = ellipsoidMesh(elli); 0015 % figure; hold on; axis equal; axis([0 100 0 100 0 100]); view(3); 0016 % drawMesh(v, f); 0017 % 0018 % See also 0019 % meshes3d, drawEllipsoid, sphereMesh, equivalentEllipsoid 0020 % 0021 0022 % ------ 0023 % Author: David Legland 0024 % E-mail: david.legland@inrae.fr 0025 % Created: 2011-03-12, using Matlab 7.9.0.529 (R2009b) 0026 % Copyright 2011-2024 INRA - Cepia Software Platform 0027 0028 %% Default values 0029 0030 % number of meridians 0031 nPhi = 32; 0032 0033 % number of parallels 0034 nTheta = 16; 0035 0036 0037 %% Extract input arguments 0038 0039 % Parse the input (try to extract center coordinates and radius) 0040 if nargin == 0 0041 % no input: assumes ellipsoid with default shape 0042 elli = [0 0 0 5 4 3 0 0 0]; 0043 end 0044 0045 % default set of options for drawing meshes 0046 options = {'FaceColor', 'g', 'linestyle', 'none'}; 0047 0048 while length(varargin) > 1 0049 switch lower(varargin{1}) 0050 case 'nphi' 0051 nPhi = varargin{2}; 0052 0053 case 'ntheta' 0054 nTheta = varargin{2}; 0055 0056 otherwise 0057 % assumes this is drawing option 0058 options = [options varargin(1:2)]; %#ok<AGROW> 0059 end 0060 0061 varargin(1:2) = []; 0062 end 0063 0064 0065 %% Parse numerical inputs 0066 0067 % Extract ellipsoid parameters 0068 xc = elli(:,1); 0069 yc = elli(:,2); 0070 zc = elli(:,3); 0071 a = elli(:,4); 0072 b = elli(:,5); 0073 c = elli(:,6); 0074 k = pi / 180; 0075 ellPhi = elli(:,7) * k; 0076 ellTheta = elli(:,8) * k; 0077 ellPsi = elli(:,9) * k; 0078 0079 0080 %% Coordinates computation 0081 0082 % convert unit basis to ellipsoid basis 0083 sca = createScaling3d(a, b, c); 0084 rotZ = createRotationOz(ellPhi); 0085 rotY = createRotationOy(ellTheta); 0086 rotX = createRotationOx(ellPsi); 0087 tra = createTranslation3d([xc yc zc]); 0088 0089 % concatenate transforms 0090 trans = tra * rotZ * rotY * rotX * sca; 0091 0092 0093 %% parametrisation of ellipsoid 0094 0095 % spherical coordinates 0096 theta = linspace(0, pi, nTheta+1); 0097 phi = linspace(0, 2*pi, nPhi+1); 0098 0099 % convert to cartesian coordinates 0100 sintheta = sin(theta); 0101 x = cos(phi') * sintheta; 0102 y = sin(phi') * sintheta; 0103 z = ones(length(phi),1) * cos(theta); 0104 0105 % transform mesh vertices 0106 [x, y, z] = transformPoint3d(x, y, z, trans); 0107 0108 % convert to FV mesh 0109 [vertices, faces] = surfToMesh(x, y, z, 'xPeriodic', false, 'yPeriodic', true); 0110 0111 % format output 0112 varargout = formatMeshOutput(nargout, vertices, faces);