Home > matGeom > geom2d > drawBezierCurve.m

drawBezierCurve

PURPOSE ^

DRAWBEZIERCURVE Draw a cubic bezier curve defined by 4 control points.

SYNOPSIS ^

function varargout = drawBezierCurve(varargin)

DESCRIPTION ^

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = drawBezierCurve(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 % ------
0030 % Author: David Legland
0031 % E-mail: david.legland@inrae.fr
0032 % Created: 2011-03-16, using Matlab 7.9.0.529 (R2009b)
0033 % Copyright 2011-2024 INRA - Cepia Software Platform
0034 
0035 % extract handle of axis to draw on
0036 if isAxisHandle(varargin{1})
0037     ax = varargin{1};
0038     varargin(1) = [];
0039 else
0040     ax = gca;
0041 end
0042 
0043 points = varargin{1};
0044 varargin(1) = [];
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 isscalar(var) && 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

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