Home > matGeom > geom2d > drawPoint.m

drawPoint

PURPOSE ^

DRAWPOINT Draw the point on the axis.

SYNOPSIS ^

function h = drawPoint(varargin)

DESCRIPTION ^

DRAWPOINT Draw the point on the axis.

   drawPoint(X, Y);
   Draws points defined by coordinates X and Y.
   X and Y should be array the same size.

   drawPoint(COORD);
   Packs coordinates in a single N-by-2 array.

   drawPoint(..., OPT);
   Draws each point with given option. OPT is a series of arguments pairs
   compatible with 'plot' model. Default drawing option is 'bo',
   corresponding to blue circles.
   If a format string is used then only the color is effective.
   Markers can be set using the 'marker' property.
   The property 'linestyle' cannot be set.

   drawPoint(AX, ...);
   Specifies the axis to draw the points in. AX should be a handle to a axis
   object. By default, display on current axis.

   H = drawPoint(...) also return a handle to each of the drawn points.

   Example
     % display a single point
     figure;
     drawPoint([10 10]);

     % display several points forming a circle
     t = linspace(0, 2*pi, 20)';
     drawPoint([5*cos(t)+10 3*sin(t)+10], 'r+');
     axis equal;

   See also
     points2d, clipPoints

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function h = drawPoint(varargin)
0002 %DRAWPOINT Draw the point on the axis.
0003 %
0004 %   drawPoint(X, Y);
0005 %   Draws points defined by coordinates X and Y.
0006 %   X and Y should be array the same size.
0007 %
0008 %   drawPoint(COORD);
0009 %   Packs coordinates in a single N-by-2 array.
0010 %
0011 %   drawPoint(..., OPT);
0012 %   Draws each point with given option. OPT is a series of arguments pairs
0013 %   compatible with 'plot' model. Default drawing option is 'bo',
0014 %   corresponding to blue circles.
0015 %   If a format string is used then only the color is effective.
0016 %   Markers can be set using the 'marker' property.
0017 %   The property 'linestyle' cannot be set.
0018 %
0019 %   drawPoint(AX, ...);
0020 %   Specifies the axis to draw the points in. AX should be a handle to a axis
0021 %   object. By default, display on current axis.
0022 %
0023 %   H = drawPoint(...) also return a handle to each of the drawn points.
0024 %
0025 %   Example
0026 %     % display a single point
0027 %     figure;
0028 %     drawPoint([10 10]);
0029 %
0030 %     % display several points forming a circle
0031 %     t = linspace(0, 2*pi, 20)';
0032 %     drawPoint([5*cos(t)+10 3*sin(t)+10], 'r+');
0033 %     axis equal;
0034 %
0035 %   See also
0036 %     points2d, clipPoints
0037 
0038 %   ---------
0039 %   author : David Legland
0040 %   INRA - TPV URPOI - BIA IMASTE
0041 %   created the 31/10/2003.
0042 %
0043 
0044 %   HISTORY
0045 %   23/02/2004 add more documentation. Manage different kind of inputs.
0046 %     Does not draw points outside visible area.
0047 %   26/02/2007 update processing of input arguments.
0048 %   30/04/2009 remove clipping of points (use clipPoints if necessary)
0049 %   2011-10-11 add management of axes handle
0050 %   2018-31-06 fix the bug reported in https://savannah.gnu.org/bugs/index.php?53659
0051 
0052 % extract handle of axis to draw on
0053 if isAxisHandle(varargin{1})
0054     ax = varargin{1};
0055     varargin(1) = [];
0056 else
0057     ax = gca;
0058 end
0059 
0060 % extract point(s) coordinates
0061 if size(varargin{1}, 2) == 2
0062     % points packed in one array
0063     var = varargin{1};
0064     px = var(:, 1);
0065     py = var(:, 2);
0066     varargin(1) = [];
0067     
0068 elseif isvector(varargin{1})
0069     % points stored in separate arrays
0070     if nargin == 1 || ~isnumeric(varargin{2})
0071         error('Missing array of y-coordinates');
0072     end
0073     px = varargin{1};
0074     py = varargin{2};
0075     varargin(1:2) = [];
0076     px = px(:);
0077     py = py(:);
0078     
0079 else
0080     error('Points should be two 1D arrays or one N-by-2 array');
0081 end
0082 
0083 if length(varargin) > 1
0084     % Check if linestyle is given
0085     char_opt = cellfun(@lower, varargin(cellfun(@ischar, varargin)), ...
0086         'UniformOutput', false);
0087     tf = ismember('linestyle', char_opt);
0088     if tf
0089         error('Points cannot be draw with lines, use plot or drawPolygon instead');
0090     end
0091     hh = plot(ax, px, py, 'marker', 'o', 'linestyle', 'none', varargin{:});
0092     
0093 elseif length(varargin) == 1
0094     % use the specified single option (for example: 'b.', or 'k+')
0095     hh = plot(ax, px, py, varargin{1});
0096 else
0097     % use a default marker
0098     hh = plot(ax, px, py, 'o');
0099 end
0100 
0101 if nargout == 1
0102     h = hh;
0103 end
0104 
0105 end

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