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 % E-mail: david.legland@inrae.fr
0041 % Created: 2003-10-31
0042 % Copyright 2003-2024 INRA - TPV URPOI - BIA IMASTE
0043 
0044 % extract handle of axis to draw in
0045 [ax, varargin] = parseAxisHandle(varargin{:});
0046 
0047 % extract point(s) coordinates
0048 if size(varargin{1}, 2) == 2
0049     % points packed in one array
0050     var = varargin{1};
0051     px = var(:, 1);
0052     py = var(:, 2);
0053     varargin(1) = [];
0054     
0055 elseif isvector(varargin{1})
0056     % points stored in separate arrays
0057     if nargin == 1 || ~isnumeric(varargin{2})
0058         error('Missing array of y-coordinates');
0059     end
0060     px = varargin{1};
0061     py = varargin{2};
0062     varargin(1:2) = [];
0063     px = px(:);
0064     py = py(:);
0065     
0066 else
0067     error('Points should be two 1D arrays or one N-by-2 array');
0068 end
0069 
0070 if length(varargin) > 1
0071     % Check if linestyle is given
0072     char_opt = cellfun(@lower, varargin(cellfun(@ischar, varargin)), ...
0073         'UniformOutput', false);
0074     tf = ismember('linestyle', char_opt);
0075     if tf
0076         error('Points cannot be draw with lines, use plot or drawPolygon instead');
0077     end
0078     hh = plot(ax, px, py, 'marker', 'o', 'linestyle', 'none', varargin{:});
0079     
0080 elseif isscalar(varargin)
0081     % use the specified single option (for example: 'b.', or 'k+')
0082     hh = plot(ax, px, py, varargin{1});
0083 else
0084     % use a default marker
0085     hh = plot(ax, px, py, 'o');
0086 end
0087 
0088 if nargout == 1
0089     h = hh;
0090 end
0091 
0092 end

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