Home > matGeom > geom2d > drawCircleArc.m

drawCircleArc

PURPOSE ^

DRAWCIRCLEARC Draw a circle arc on the current axis.

SYNOPSIS ^

function varargout = drawCircleArc(varargin)

DESCRIPTION ^

DRAWCIRCLEARC Draw a circle arc on the current axis.

   drawCircleArc(ARC);
   Draws circle arc defined by ARC = [XC YC R START EXTENT], with (XC, YC)
   being the circle center, R being the circle radius, starting from angle 
   START, and with angular extent given by EXTENT. START and EXTENT angles
   are given in degrees.

   drawCircleArc(XC, YC, R, START, EXTENT);
   Alternative syntax that seperates inputs.

   drawCircleArc(..., PARAM, VALUE);
   specifies plot properties by using one or several parameter name-value
   pairs.

   drawCircleArc(AX, ...);
   Specifies handle of the axis to draw on.

   H = drawCircleArc(...);
   Returns a handle to the created line object.

   Example
     % Draw a red thick circle arc
     arc = [10 20 30 -120 240];
     figure;
     axis([-50 100 -50 100]);
     hold on
     drawCircleArc(arc, 'LineWidth', 3, 'Color', 'r')

   See also
     circles2d, drawCircle, drawEllipse, circleArcToPolyline

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = drawCircleArc(varargin)
0002 %DRAWCIRCLEARC Draw a circle arc on the current axis.
0003 %
0004 %   drawCircleArc(ARC);
0005 %   Draws circle arc defined by ARC = [XC YC R START EXTENT], with (XC, YC)
0006 %   being the circle center, R being the circle radius, starting from angle
0007 %   START, and with angular extent given by EXTENT. START and EXTENT angles
0008 %   are given in degrees.
0009 %
0010 %   drawCircleArc(XC, YC, R, START, EXTENT);
0011 %   Alternative syntax that seperates inputs.
0012 %
0013 %   drawCircleArc(..., PARAM, VALUE);
0014 %   specifies plot properties by using one or several parameter name-value
0015 %   pairs.
0016 %
0017 %   drawCircleArc(AX, ...);
0018 %   Specifies handle of the axis to draw on.
0019 %
0020 %   H = drawCircleArc(...);
0021 %   Returns a handle to the created line object.
0022 %
0023 %   Example
0024 %     % Draw a red thick circle arc
0025 %     arc = [10 20 30 -120 240];
0026 %     figure;
0027 %     axis([-50 100 -50 100]);
0028 %     hold on
0029 %     drawCircleArc(arc, 'LineWidth', 3, 'Color', 'r')
0030 %
0031 %   See also
0032 %     circles2d, drawCircle, drawEllipse, circleArcToPolyline
0033 %
0034 
0035 % ------
0036 % Author: David Legland
0037 % E-mail: david.legland@inrae.fr
0038 % Created: 2003-12-12
0039 % Copyright 2003-2024 INRA - TPV URPOI - BIA IMASTE
0040 
0041 %% Parse input arguments
0042 
0043 % extract handle of axis to draw on
0044 [ax, varargin] = parseAxisHandle(varargin{:});
0045 
0046 circle = varargin{1};
0047 if size(circle, 2) == 5
0048     x0  = circle(:,1);
0049     y0  = circle(:,2);
0050     r   = circle(:,3);
0051     start   = circle(:,4);
0052     extent  = circle(:,5);
0053     varargin(1) = [];
0054     
0055 elseif length(varargin) >= 5
0056     x0  = varargin{1};
0057     y0  = varargin{2};
0058     r   = varargin{3};
0059     start   = varargin{4};
0060     extent  = varargin{5};
0061     varargin(1:5) = [];
0062     
0063 else
0064     error('drawCircleArc: please specify center, radius and angles of circle arc');
0065 end
0066 
0067 
0068 %% Pre-processing
0069 
0070 % convert angles in radians
0071 t0  = deg2rad(start);
0072 t1  = t0 + deg2rad(extent);
0073 
0074 % number of line segments
0075 N = 60;
0076 
0077 % initialize handles vector
0078 h   = zeros(length(x0), 1);
0079 
0080 % save hold state
0081 holdState = ishold(ax);
0082 hold(ax, 'on');
0083 
0084 
0085 %% Display each circle arc
0086 
0087 % draw each circle arc individually
0088 for i = 1:length(x0)
0089     % compute basis
0090     t = linspace(t0(i), t1(i), N+1)';
0091 
0092     % compute vertices coordinates
0093     xt = x0(i) + r(i)*cos(t);
0094     yt = y0(i) + r(i)*sin(t);
0095     
0096     % draw the circle arc
0097     h(i) = plot(ax, xt, yt, varargin{:});
0098 end
0099 
0100 
0101 %% post-processing
0102 
0103 % restore hold state
0104 if ~holdState
0105     hold(ax, 'off');
0106 end
0107 
0108 if nargout > 0
0109     varargout = {h};
0110 end

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022