Home > matGeom > geom3d > drawTorus.m

drawTorus

PURPOSE ^

DRAWTORUS Draw a torus (3D ring).

SYNOPSIS ^

function varargout = drawTorus(torus, varargin)

DESCRIPTION ^

DRAWTORUS Draw a torus (3D ring).

   drawTorus(TORUS)
   Draws the torus on the current axis. TORUS is given by:
   [XC YC ZY  R1 R2  THETA PHI]
   where (XC YZ ZC) is the center of the torus, R1 is the main radius, R2
   is the radius of the torus section, and (THETA PHI) is the angle of the
   torus normal vector (both in degrees).

   drawTorus(..., PNAME, PVALUE)
   Specifies a set of parameter name-value pairs. Parameter names include
   plitting options ('facecolor', 'linestyle'...), or options specific to
   torus:
   'nPhi'      number of meridians used to draw the torus (default is 60).
   'nTheta'    number of parallels used to draw the torus (default is 60).


   Example
     % draw sample torus
     figure;
     drawTorus([50 50 50 30 10 30 45]);
     axis equal; view([95 10]); light;

   See also
   drawEllipsoid, revolutionSurface, torusMesh

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = drawTorus(torus, varargin)
0002 %DRAWTORUS Draw a torus (3D ring).
0003 %
0004 %   drawTorus(TORUS)
0005 %   Draws the torus on the current axis. TORUS is given by:
0006 %   [XC YC ZY  R1 R2  THETA PHI]
0007 %   where (XC YZ ZC) is the center of the torus, R1 is the main radius, R2
0008 %   is the radius of the torus section, and (THETA PHI) is the angle of the
0009 %   torus normal vector (both in degrees).
0010 %
0011 %   drawTorus(..., PNAME, PVALUE)
0012 %   Specifies a set of parameter name-value pairs. Parameter names include
0013 %   plitting options ('facecolor', 'linestyle'...), or options specific to
0014 %   torus:
0015 %   'nPhi'      number of meridians used to draw the torus (default is 60).
0016 %   'nTheta'    number of parallels used to draw the torus (default is 60).
0017 %
0018 %
0019 %   Example
0020 %     % draw sample torus
0021 %     figure;
0022 %     drawTorus([50 50 50 30 10 30 45]);
0023 %     axis equal; view([95 10]); light;
0024 %
0025 %   See also
0026 %   drawEllipsoid, revolutionSurface, torusMesh
0027 %
0028 
0029 % ------
0030 % Author: David Legland
0031 % e-mail: david.legland@grignon.inra.fr
0032 % Created: 2011-06-22,    using Matlab 7.9.0.529 (R2009b)
0033 % Copyright 2011 INRA - Cepia Software Platform.
0034 
0035 %% Default values
0036 
0037 % number of meridians
0038 nPhi    = 60;
0039 
0040 % number of parallels
0041 nTheta  = 60;
0042 
0043 
0044 %% Extract input arguments
0045 
0046 center = torus(1:3);
0047 r1 = torus(4);
0048 r2 = torus(5);
0049 
0050 normal = [0 0];
0051 if size(torus, 2) >= 7
0052     normal = torus(6:7);
0053 end
0054 
0055 % default set of options for drawing meshes
0056 options = {'FaceColor', 'g', 'linestyle', 'none'};
0057 
0058 while length(varargin) > 1
0059     switch lower(varargin{1})
0060         case 'nphi'
0061             nPhi = varargin{2};
0062             
0063         case 'ntheta'
0064             nTheta = varargin{2};
0065 
0066         otherwise
0067             % assumes this is drawing option
0068             options = [options varargin(1:2)]; %#ok<AGROW>
0069     end
0070 
0071     varargin(1:2) = [];
0072 end
0073 
0074 
0075 %% Draw the torus
0076 
0077 % create base torus
0078 circle = circleToPolygon([r1 0 r2], nTheta);
0079 [x, y, z] = revolutionSurface(circle, linspace(0, 2*pi, nPhi));
0080 
0081 % transform torus
0082 trans = localToGlobal3d([center normal]);
0083 [x, y, z] = transformPoint3d(x, y, z, trans);
0084 
0085 % draw the surface
0086 hs = surf(x, y, z, options{:});
0087 
0088 
0089 %% Process output arguments
0090 
0091 if nargout > 0
0092     varargout = {hs};
0093 end

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