## Copyright (C) 2017 Fabian Alexander Wilms ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your Value) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} viscircles (@var{centers}, @var{radii}) ## @deftypefnx {Function File} viscircles (@var{ax}, @var{centers}, @var{radii}) ## @deftypefnx {Function File} {@var{h} =} viscircles (@var{ax}, @var{centers}, @var{radii}) ## @deftypefnx {Function File} {@var{h} =} viscircles (@var{___}, @var{name}, @var{value}) ## Draws circles with specified centers and radii on top of the current or given axes. ## ## The function accepts the following arguments: ## ## @var{centers}: Nx2 vector of the x and y coordinates of the circles' centers. ## ## Example: ## ## x y ## ## [10 20; center 1 ## ## -10 -20] center 2 ## ## @var{RADII}: Nx1 vector of the circles' radii ## ## @var{ax}: The axes on top of which the circles should be drawn ## ## Multiple property-value pairs may be specified, but they must ## appear in pairs. These arguments are applied to the line objects ## drawn by 'viscircles'. Allowed properties to modify are @var{linestyle}, ## @var{linewidth}, @var{color}, @var{enhancevisibility} and @var{edgecolor}. ## ## @table @var ## @item color ## ## @multitable @columnfractions 0.06 0.94 ## @item @samp{k} @tab blacK ## @item @samp{r} @tab Red (dafault) ## @item @samp{g} @tab Green ## @item @samp{b} @tab Blue ## @item @samp{y} @tab Yellow ## @item @samp{m} @tab Magenta ## @item @samp{c} @tab Cyan ## @item @samp{w} @tab White ## @end multitable ## ## @item linestyle ## ## @multitable @columnfractions 0.06 0.94 ## @item @samp{-} @tab Use solid lines (default). ## @item @samp{--} @tab Use dashed lines. ## @item @samp{:} @tab Use dotted lines. ## @item @samp{-.} @tab Use dash-dotted lines. ## @end multitable ## ## @item linewidth ## @multitable @columnfractions 0.25 0.75 ## @item positive value @tab Set the line width (default: 2) ## @end multitable ## ## @item enhancevisibility ## ## @multitable @columnfractions 0.1 0.9 ## @item @samp{false} @tab Don't do anything (default) ## @item @samp{true} @tab Draw a white circle below each of the circles. ## @end multitable ## ## @end table ## @var{edgecolor} ## @item @tab Same options and effect as the @var{color} property ## Author: Fabian Alexander Wilms function h = viscircles (varargin) nargs = length(varargin); # Input check if (nargs < 2) print_usage (); endif # Set default values enhance_visibility_value = true; color_value = "red"; line_style_value = "-"; line_width_value = 2; # Extract arguments try get (varargin{1},"type") ax = varargin{1}; centers = varargin{2}; radii = varargin{3}; catch ax = gca; centers = varargin{1}; radii = varargin{2}; end # Input checks if (ismatrix(centers) ~= 1) error('CENTERS must be a Nx2 vector'); endif if (size(centers)(2) ~= 2) error('CENTERS must be a Nx2 vector'); endif if (size(radii)(2) ~= 1) error('RADII must be a Nx1 vector'); endif if (size(centers)(1) ~= size(radii)(1)) error('CENTERS and RADII vectors must have the same length'); endif # Extract additional arguments argument_position = find (cellfun (@ (x) strcmpi (x, "EnhanceVisibility") , varargin)); if (argument_position) enhance_visibility_value = varargin{argument_position+1}; endif argument_position = find (cellfun (@ (x) strcmpi (x, "Color") , varargin)); if (argument_position) color_value = varargin{argument_position+1}; endif argument_position = find (cellfun (@ (x) strcmpi (x, "LineStyle") , varargin)); if (argument_position) line_style_value = varargin{argument_position+1}; endif argument_position = find (cellfun (@ (x) strcmpi (x, "LineWidth") , varargin)); if (argument_position) line_width_value = varargin{argument_position+1}; endif # This property isn't documented here: https://mathworks.com/help/images/ref/viscircles.html # But it is used here: https://mathworks.com/help/images/ref/imfindcircles.html argument_position = find (cellfun (@ (x) strcmpi (x, "EdgeColor") , varargin)); if (argument_position) color_value = varargin{argument_position+1}; endif # Plot circles hold on alpha_samples = 0:2*pi/100:2*pi; for i=1:size (centers)(1) x_samples = radii (i) * cos (alpha_samples) + centers (i,1); y_samples = radii (i) * sin (alpha_samples) + centers (i,2); if (enhance_visibility_value) plot (ax, x_samples, y_samples, "Color", "white", "LineStyle", "-", "LineWidth", line_width_value+2); endif plot (ax, x_samples, y_samples, "Color", color_value, "LineStyle", line_style_value, "LineWidth", line_width_value); endfor hold off h = hggroup (); endfunction %!demo %! centers = randi ([0 100],5,2); %! radii = randi ([0 100],5,1); %! axis equal %! viscircles (centers, radii,'Color','magenta','LineStyle',':','LineWidth',5); %! title ("5 random circles"); %! #------------------------------------------------- %! # the figure window shows 5 circles with random %! # radii and positions %!test %! centers = randi ([0 100],5,2); %! radii = randi ([0 100],5,1); %! h = viscircles (centers, radii); %! close; %!test %! centers = randi ([0 100],5,2); %! radii = randi ([0 100],5,1); %! figure (); %! h = viscircles (gca, centers, radii); %! close; %!test %! centers = randi ([0 100],5,2); %! radii = randi ([0 100],5,1); %! h = viscircles (centers, radii,'Color','magenta','LineStyle',':','LineWidth',5); %! close; %!test %! centers = randi ([0 100],5,2); %! radii = randi ([0 100],5,1); %! figure (); %! h = viscircles (gca, centers, radii,'Color','magenta','LineStyle',':','LineWidth',5); %! close;