DRAWBEZIERCURVE Draw a cubic bezier curve defined by 4 control points. drawBezierCurve(POINTS) Draw the Bezier curve defined by the 4 control points stored in POINTS. POINTS is either a 4-by-2 array (vertical concatenation of control points coordinates), or a 1-by-8 array (horizontal concatenation of control point coordinates). drawBezierCurve(..., PARAM, VALUE) Specifies additional drawing parameters, see the line function for details. drawBezierCurve(AX, ...); Spcifies the handle of the axis to draw on. H = drawBezierCurve(...); Return a handle to the created graphic object. Example drawBezierCurve([0 0;5 10;10 5;10 0]); drawBezierCurve([0 0;5 10;10 5;10 0], 'linewidth', 2, 'color', 'g'); See also drawPolyline, cubicBezierToPolyline ------ Author: David Legland e-mail: david.legland@grignon.inra.fr Created: 2011-03-16, using Matlab 7.9.0.529 (R2009b) Copyright 2011 INRA - Cepia Software Platform.
0001 function varargout = drawBezierCurve(points, varargin) 0002 %DRAWBEZIERCURVE Draw a cubic bezier curve defined by 4 control points. 0003 % 0004 % drawBezierCurve(POINTS) 0005 % Draw the Bezier curve defined by the 4 control points stored in POINTS. 0006 % POINTS is either a 4-by-2 array (vertical concatenation of control 0007 % points coordinates), or a 1-by-8 array (horizontal concatenation of 0008 % control point coordinates). 0009 % 0010 % drawBezierCurve(..., PARAM, VALUE) 0011 % Specifies additional drawing parameters, see the line function for 0012 % details. 0013 % 0014 % drawBezierCurve(AX, ...); 0015 % Spcifies the handle of the axis to draw on. 0016 % 0017 % H = drawBezierCurve(...); 0018 % Return a handle to the created graphic object. 0019 % 0020 % 0021 % Example 0022 % drawBezierCurve([0 0;5 10;10 5;10 0]); 0023 % drawBezierCurve([0 0;5 10;10 5;10 0], 'linewidth', 2, 'color', 'g'); 0024 % 0025 % See also 0026 % drawPolyline, cubicBezierToPolyline 0027 % 0028 % ------ 0029 % Author: David Legland 0030 % e-mail: david.legland@grignon.inra.fr 0031 % Created: 2011-03-16, using Matlab 7.9.0.529 (R2009b) 0032 % Copyright 2011 INRA - Cepia Software Platform. 0033 0034 % HISTORY 0035 % 2011-10-11 add management of axes handle 0036 0037 % extract handle of axis to draw on 0038 if isAxisHandle(points) 0039 ax = points; 0040 points = varargin{1}; 0041 varargin(1) = []; 0042 else 0043 ax = gca; 0044 end 0045 0046 % default number of discretization steps 0047 N = 64; 0048 0049 % check if discretization step is specified 0050 if ~isempty(varargin) 0051 var = varargin{1}; 0052 if length(var) == 1 && isnumeric(var) 0053 N = round(var); 0054 varargin(1) = []; 0055 end 0056 end 0057 0058 % convert control coordinates to polyline 0059 poly = cubicBezierToPolyline(points, N); 0060 0061 % draw the curve 0062 h = drawPolyline(ax, poly, varargin{:}); 0063 0064 % eventually return a handle to the created object 0065 if nargout > 0 0066 varargout = {h}; 0067 end