Home > matGeom > geom2d > drawEllipseArc.m

drawEllipseArc

PURPOSE ^

DRAWELLIPSEARC Draw an ellipse arc on the current axis.

SYNOPSIS ^

function varargout = drawEllipseArc(varargin)

DESCRIPTION ^

DRAWELLIPSEARC Draw an ellipse arc on the current axis.

   drawEllipseArc(ARC) 
   draw ellipse arc specified by ARC. ARC has the format:
     ARC = [XC YC A B THETA T1 T2]
   or:
     ARC = [XC YC A B T1 T2] (isothetic ellipse)
   with center (XC, YC), main axis of half-length A, second axis of
   half-length B, and ellipse arc running from t1 to t2 (both in degrees,
   in Counter-Clockwise orientation).

   Parameters can also be arrays. In this case, all arrays are suposed to
   have the same size...

   drawEllipseArc(..., NAME, VALUE)
   Specifies one or more parameters name-value pairs, as in the plot
   function.

   drawEllipseArc(AX, ...)
   Sepcifies the handle of theaxis to draw on.

   H = drawEllipseArc(...)
   Returns handle(s) of the created graphic objects.

   Example
     % draw an ellipse arc: center = [10 20], radii = 50 and 30, theta = 45
     arc = [10 20 50 30 45 -90 270];
     figure;
     axis([-50 100 -50 100]); axis equal;
     hold on
     drawEllipseArc(arc, 'color', 'r')

     % draw another ellipse arc, between angles -60 and 70
     arc = [10 20 50 30 45 -60 (60+70)];
     figure;
     axis([-50 100 -50 100]); axis equal;
     hold on
     drawEllipseArc(arc, 'LineWidth', 2);
     ray1 = createRay([10 20], deg2rad(-60+45));
     drawRay(ray1)
     ray2 = createRay([10 20], deg2rad(70+45));
     drawRay(ray2)

   See also:
   ellipses2d, drawEllipse, drawCircleArc

   ---------
   author : David Legland
   INRA - TPV URPOI - BIA IMASTE
   created the 12/12/2003.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = drawEllipseArc(varargin)
0002 %DRAWELLIPSEARC Draw an ellipse arc on the current axis.
0003 %
0004 %   drawEllipseArc(ARC)
0005 %   draw ellipse arc specified by ARC. ARC has the format:
0006 %     ARC = [XC YC A B THETA T1 T2]
0007 %   or:
0008 %     ARC = [XC YC A B T1 T2] (isothetic ellipse)
0009 %   with center (XC, YC), main axis of half-length A, second axis of
0010 %   half-length B, and ellipse arc running from t1 to t2 (both in degrees,
0011 %   in Counter-Clockwise orientation).
0012 %
0013 %   Parameters can also be arrays. In this case, all arrays are suposed to
0014 %   have the same size...
0015 %
0016 %   drawEllipseArc(..., NAME, VALUE)
0017 %   Specifies one or more parameters name-value pairs, as in the plot
0018 %   function.
0019 %
0020 %   drawEllipseArc(AX, ...)
0021 %   Sepcifies the handle of theaxis to draw on.
0022 %
0023 %   H = drawEllipseArc(...)
0024 %   Returns handle(s) of the created graphic objects.
0025 %
0026 %   Example
0027 %     % draw an ellipse arc: center = [10 20], radii = 50 and 30, theta = 45
0028 %     arc = [10 20 50 30 45 -90 270];
0029 %     figure;
0030 %     axis([-50 100 -50 100]); axis equal;
0031 %     hold on
0032 %     drawEllipseArc(arc, 'color', 'r')
0033 %
0034 %     % draw another ellipse arc, between angles -60 and 70
0035 %     arc = [10 20 50 30 45 -60 (60+70)];
0036 %     figure;
0037 %     axis([-50 100 -50 100]); axis equal;
0038 %     hold on
0039 %     drawEllipseArc(arc, 'LineWidth', 2);
0040 %     ray1 = createRay([10 20], deg2rad(-60+45));
0041 %     drawRay(ray1)
0042 %     ray2 = createRay([10 20], deg2rad(70+45));
0043 %     drawRay(ray2)
0044 %
0045 %   See also:
0046 %   ellipses2d, drawEllipse, drawCircleArc
0047 %
0048 %   ---------
0049 %   author : David Legland
0050 %   INRA - TPV URPOI - BIA IMASTE
0051 %   created the 12/12/2003.
0052 %
0053 
0054 
0055 %   HISTORY
0056 %   2008/10/10 uses fixed number of points for arc.
0057 %   2011-03-30 use angles in degrees
0058 %   2011-10-11 add management of axes handle
0059 
0060 %% Extract input arguments
0061 
0062 % extract handle of axis to draw on
0063 if isAxisHandle(varargin{1})
0064     ax = varargin{1};
0065     varargin(1) = [];
0066 else
0067     ax = gca;
0068 end
0069 
0070 % extract dawing style strings
0071 styles = {};
0072 for i = 1:length(varargin)
0073     if ischar(varargin{i})
0074         styles = varargin(i:end);
0075         varargin(i:end) = [];
0076         break;
0077     end
0078 end
0079 
0080 if length(varargin)==1
0081     ellipse = varargin{1};
0082     x0 = ellipse(1);
0083     y0 = ellipse(2);
0084     a  = ellipse(3);
0085     b  = ellipse(4);
0086     if size(ellipse, 2)>6
0087         theta   = ellipse(5);
0088         start   = ellipse(6);
0089         extent  = ellipse(7);
0090     else
0091         theta   = zeros(size(x0));
0092         start   = ellipse(5);
0093         extent  = ellipse(6);
0094     end
0095     
0096 elseif length(varargin)>=6
0097     x0 = varargin{1};
0098     y0 = varargin{2};
0099     a  = varargin{3};
0100     b  = varargin{4};
0101     if length(varargin)>6
0102         theta   = varargin{5};
0103         start   = varargin{6};
0104         extent  = varargin{7};
0105     else
0106         theta   = zeros(size(x0));
0107         start   = varargin{5};
0108         extent  = varargin{6};
0109     end
0110     
0111 else
0112     error('drawEllipseArc: please specify center x, center y and radii a and b');
0113 end
0114 
0115 
0116 %% Drawing
0117 
0118 % allocate memory for handles
0119 h = zeros(size(x0));
0120 
0121 for i = 1:length(x0)
0122     % start and end angles
0123     t1 = deg2rad(start);
0124     t2 = t1 + deg2rad(extent);
0125     
0126     % vertices of ellipse
0127     t = linspace(t1, t2, 60);
0128     
0129     % convert angles to ellipse parametrisation
0130     sup = cos(t) > 0;
0131     t(sup)  = atan(a(i) / b(i) * tan(t(sup)));
0132     t(~sup) = atan2(a(i) / b(i) * tan(2*pi - t(~sup)), -1);
0133     t = mod(t, 2*pi);
0134     
0135     % precompute cos and sin of theta (given in degrees)
0136     cot = cosd(theta(i));
0137     sit = sind(theta(i));
0138 
0139     % compute position of points
0140     xt = x0(i) + a(i)*cos(t)*cot - b(i)*sin(t)*sit;
0141     yt = y0(i) + a(i)*cos(t)*sit + b(i)*sin(t)*cot;
0142     
0143     h(i) = plot(ax, xt, yt, styles{:});
0144 end
0145 
0146 
0147 %% Process output arguments
0148 
0149 if nargout > 0
0150     varargout = {h};
0151 end

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