Home > matGeom > meshes3d > ellipsoidMesh.m

ellipsoidMesh

PURPOSE ^

ELLIPSOIDMESH Convert a 3D ellipsoid to face-vertex mesh representation.

SYNOPSIS ^

function varargout = ellipsoidMesh(elli, varargin)

DESCRIPTION ^

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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@grignon.inra.fr
0025 % Created: 2011-03-12,    using Matlab 7.9.0.529 (R2009b)
0026 % Copyright 2011 INRA - Cepia Software Platform.
0027 
0028 
0029 %% Default values
0030 
0031 % number of meridians
0032 nPhi    = 32;
0033 
0034 % number of parallels
0035 nTheta  = 16;
0036 
0037 
0038 %% Extract input arguments
0039 
0040 % Parse the input (try to extract center coordinates and radius)
0041 if nargin == 0
0042     % no input: assumes ellipsoid with default shape
0043     elli = [0 0 0 5 4 3 0 0 0];
0044 end
0045 
0046 % default set of options for drawing meshes
0047 options = {'FaceColor', 'g', 'linestyle', 'none'};
0048 
0049 while length(varargin) > 1
0050     switch lower(varargin{1})
0051         case 'nphi'
0052             nPhi = varargin{2};
0053             
0054         case 'ntheta'
0055             nTheta = varargin{2};
0056 
0057         otherwise
0058             % assumes this is drawing option
0059             options = [options varargin(1:2)]; %#ok<AGROW>
0060     end
0061 
0062     varargin(1:2) = [];
0063 end
0064 
0065 
0066 %% Parse numerical inputs
0067 
0068 % Extract ellipsoid parameters
0069 xc  = elli(:,1);
0070 yc  = elli(:,2);
0071 zc  = elli(:,3);
0072 a   = elli(:,4);
0073 b   = elli(:,5);
0074 c   = elli(:,6);
0075 k   = pi / 180;
0076 ellPhi   = elli(:,7) * k;
0077 ellTheta = elli(:,8) * k;
0078 ellPsi   = elli(:,9) * k;
0079 
0080 
0081 %% Coordinates computation
0082 
0083 % convert unit basis to ellipsoid basis
0084 sca     = createScaling3d(a, b, c);
0085 rotZ    = createRotationOz(ellPhi);
0086 rotY    = createRotationOy(ellTheta);
0087 rotX    = createRotationOx(ellPsi);
0088 tra     = createTranslation3d([xc yc zc]);
0089 
0090 % concatenate transforms
0091 trans   = tra * rotZ * rotY * rotX * sca;
0092 
0093 
0094 %% parametrisation of ellipsoid
0095 
0096 % spherical coordinates
0097 theta   = linspace(0, pi, nTheta+1);
0098 phi     = linspace(0, 2*pi, nPhi+1);
0099 
0100 % convert to cartesian coordinates
0101 sintheta = sin(theta);
0102 x = cos(phi') * sintheta;
0103 y = sin(phi') * sintheta;
0104 z = ones(length(phi),1) * cos(theta);
0105 
0106 % transform mesh vertices
0107 [x, y, z] = transformPoint3d(x, y, z, trans);
0108 
0109 % convert to FV mesh
0110 [vertices, faces] = surfToMesh(x, y, z, 'xPeriodic', false, 'yPeriodic', true);
0111 
0112 % format output
0113 varargout = formatMeshOutput(nargout, vertices, faces);

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019