<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>k-Wave User Forum &#187; Topic: modification of makeCartCircle and makeCircle</title>
		<link>http://www.k-wave.org/forum/topic/modification-of-makecartcircle-and-makecircle</link>
		<description>Support for the k-Wave MATLAB toolbox</description>
		<language>en-US</language>
		<pubDate>Wed, 13 May 2026 00:22:13 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.k-wave.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.k-wave.org/forum/rss/topic/modification-of-makecartcircle-and-makecircle" rel="self" type="application/rss+xml" />

		<item>
			<title>Bradley Treeby on "modification of makeCartCircle and makeCircle"</title>
			<link>http://www.k-wave.org/forum/topic/modification-of-makecartcircle-and-makecircle#post-1217</link>
			<pubDate>Tue, 05 Feb 2013 16:12:26 +0000</pubDate>
			<dc:creator>Bradley Treeby</dc:creator>
			<guid isPermaLink="false">1217@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi Chao,&#60;/p&#62;
&#60;p&#62;That's a useful modification - a few people have asked about doing exactly that. Thanks for posting! We'll look at incorporating into the next release.&#60;/p&#62;
&#60;p&#62;Brad.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>huangchao on "modification of makeCartCircle and makeCircle"</title>
			<link>http://www.k-wave.org/forum/topic/modification-of-makecartcircle-and-makecircle#post-1216</link>
			<pubDate>Tue, 05 Feb 2013 02:13:54 +0000</pubDate>
			<dc:creator>huangchao</dc:creator>
			<guid isPermaLink="false">1216@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi Dr. Treeby,&#60;/p&#62;
&#60;p&#62;In the original makeCartCircle and makeCircle functions, the argument arc_angle should be a scalar, which means the start point of the arc angle is fixed to be 0 radians. So to allow users to specify the start point and end point of the arc angle, I modified makeCartCircle and makeCircle so that arc_angle can be in form of [angle0, angle1], where angle0 and angle1 are the start and end of the arc angle, respectively. It requires 0&#38;lt;=angle0&#38;lt;angle1&#38;lt;=2*pi. Here are the modified codes:&#60;/p&#62;
&#60;p&#62;function circle = makeCartCircle(radius, num_points, center_pos, arc_angle, plot_circle)&#60;br /&#62;
%MAKECARTCIRCLE     Create a 2D Cartesian circle or arc.&#60;br /&#62;
%&#60;br /&#62;
% DESCRIPTION:&#60;br /&#62;
%       MakeCartCircle creates a 2 x num_points array of the Cartesian&#60;br /&#62;
%       coordinates of points evenly distributed over a circle or arc (if&#60;br /&#62;
%       arc_angle is given).&#60;br /&#62;
%&#60;br /&#62;
% USAGE:&#60;br /&#62;
%       circle = makeCartCircle(radius, num_points)&#60;br /&#62;
%       circle = makeCartCircle(radius, num_points, center_pos)&#60;br /&#62;
%       circle = makeCartCircle(radius, num_points, center_pos, arc_angle)&#60;br /&#62;
%       circle = makeCartCircle(radius, num_points, center_pos, arc_angle, plot_circle)&#60;br /&#62;
%&#60;br /&#62;
% INPUTS:&#60;br /&#62;
%       radius          - circle radius [m]&#60;br /&#62;
%       num_points      - number of points in the circle&#60;br /&#62;
%&#60;br /&#62;
% OPTIONAL INPUTS:&#60;br /&#62;
%       center_pos      - [x, y] position of the circle center [m]&#60;br /&#62;
%                         (default = [0, 0])&#60;br /&#62;
%       arc_angle       - arc angle for incomplete circle [radians]&#60;br /&#62;
%                         (default = 2*pi)&#60;br /&#62;
%       plot_circle     - Boolean controlling whether the Cartesian points&#60;br /&#62;
%                         are plotted (default = false)&#60;br /&#62;
%&#60;br /&#62;
% OUTPUTS:&#60;br /&#62;
%       circle          - 2 x num_points array of Cartesian coordinates&#60;br /&#62;
%&#60;br /&#62;
% ABOUT:&#60;br /&#62;
%       author          - Bradley Treeby&#60;br /&#62;
%       date            - 5th June 2009&#60;br /&#62;
%       last update     - 21st September 2012&#60;br /&#62;
%&#60;br /&#62;
% This function is part of the k-Wave Toolbox (&#60;a href=&#34;http://www.k-wave.org&#34; rel=&#34;nofollow&#34;&#62;http://www.k-wave.org&#60;/a&#62;)&#60;br /&#62;
% Copyright (C) 2009-2012 Bradley Treeby and Ben Cox&#60;br /&#62;
%&#60;br /&#62;
% See also cart2grid, makeCartSphere, makeCircle&#60;/p&#62;
&#60;p&#62;% This file is part of k-Wave. k-Wave is free software: you can&#60;br /&#62;
% redistribute it and/or modify it under the terms of the GNU Lesser&#60;br /&#62;
% General Public License as published by the Free Software Foundation,&#60;br /&#62;
% either version 3 of the License, or (at your option) any later version.&#60;br /&#62;
%&#60;br /&#62;
% k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY&#60;br /&#62;
% WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS&#60;br /&#62;
% FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for&#60;br /&#62;
% more details.&#60;br /&#62;
%&#60;br /&#62;
% You should have received a copy of the GNU Lesser General Public License&#60;br /&#62;
% along with k-Wave. If not, see &#38;lt;http://www.gnu.org/licenses/&#38;gt;.&#60;/p&#62;
&#60;p&#62;% check for plot_circle input&#60;br /&#62;
if nargin &#38;lt; 5&#60;br /&#62;
    plot_circle = false;&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;% check for arc_angle input&#60;br /&#62;
if nargin &#38;lt; 4&#60;br /&#62;
    angle0 = 0;&#60;br /&#62;
    angle_range = 2*pi;&#60;br /&#62;
    full_circle = true;&#60;br /&#62;
elseif numel(arc_angle) == 1&#60;br /&#62;
    angle0 = 0;&#60;br /&#62;
    angle_range = arc_angle;&#60;br /&#62;
    if arc_angle == 2*pi;&#60;br /&#62;
        full_circle = true;&#60;br /&#62;
    else&#60;br /&#62;
        full_circle = false;&#60;br /&#62;
    end&#60;br /&#62;
else&#60;br /&#62;
    angle0 = arc_angle(1);&#60;br /&#62;
    angle_range = arc_angle(2) - arc_angle(1);&#60;br /&#62;
    if arc_angle(1) == 0 &#38;amp;&#38;amp; arc_angle(1) == 2*pi&#60;br /&#62;
        full_circle = true;&#60;br /&#62;
    else&#60;br /&#62;
        full_circle = false;&#60;br /&#62;
    end&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;% check for center_pos input&#60;br /&#62;
if nargin &#38;lt; 3 &#124;&#124; isempty(center_pos)&#60;br /&#62;
    cx = 0;&#60;br /&#62;
    cy = 0;&#60;br /&#62;
else&#60;br /&#62;
    cx = center_pos(1);&#60;br /&#62;
    cy = center_pos(2);&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;% ensure there is only a total of num_points including the endpoints when&#60;br /&#62;
% arc_angle is not equal to 2*pi&#60;br /&#62;
if ~full_circle&#60;br /&#62;
    num_points = num_points - 1;&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;% create angles&#60;br /&#62;
angles = (0:(num_points))*angle_range/(num_points) + angle0 + pi/2;&#60;/p&#62;
&#60;p&#62;% discard repeated final point if arc_angle is equal to 2*pi&#60;br /&#62;
if full_circle&#60;br /&#62;
    angles = angles(1:end-1);&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;% create cartesian grid&#60;br /&#62;
% circle = flipud([radius*cos(angles); radius*sin(-angles)]);   % B.0.3&#60;br /&#62;
circle = ([radius*cos(angles); radius*sin(-angles)]);           % B.0.4&#60;/p&#62;
&#60;p&#62;% offset if needed&#60;br /&#62;
circle(1, :) = circle(1, :) + cx;&#60;br /&#62;
circle(2, :) = circle(2, :) + cy;&#60;/p&#62;
&#60;p&#62;% plot results&#60;br /&#62;
if plot_circle&#60;/p&#62;
&#60;p&#62;    % select suitable axis scaling factor&#60;br /&#62;
    [x_sc, scale, prefix] = scaleSI(max(abs(circle(:)))); &#60;/p&#62;
&#60;p&#62;    % create the figure&#60;br /&#62;
    figure;&#60;br /&#62;
    plot(circle(2,:)*scale, circle(1,:)*scale, 'b.');&#60;br /&#62;
    set(gca, 'YDir', 'reverse');&#60;br /&#62;
    xlabel(['y-position [' prefix 'm]']);&#60;br /&#62;
    ylabel(['x-position [' prefix 'm]']);&#60;br /&#62;
    axis equal;&#60;/p&#62;
&#60;p&#62;end&#60;/p&#62;
&#60;p&#62;function circle = makeCircle(Nx, Ny, cx, cy, radius, arc_angle, plot_circle)&#60;br /&#62;
%MAKECIRCLE     Create a binary map of a circle within a 2D grid.&#60;br /&#62;
%&#60;br /&#62;
% DESCRIPTION:&#60;br /&#62;
%       makeCircle creates a binary map of a circle or arc (using the&#60;br /&#62;
%       midpoint circle algorithm) within a two-dimensional grid (the&#60;br /&#62;
%       circle position is denoted by 1's in the matrix with 0's&#60;br /&#62;
%       elsewhere). A single grid point is taken as the circle centre thus&#60;br /&#62;
%       the total diameter will always be an odd number of grid points.&#60;br /&#62;
%&#60;br /&#62;
% USAGE:&#60;br /&#62;
%       circle = makeCircle(Nx, Ny, cx, cy, radius)&#60;br /&#62;
%       circle = makeCircle(Nx, Ny, cx, cy, radius, arc_angle)&#60;br /&#62;
%       circle = makeCircle(Nx, Ny, cx, cy, radius, arc_angle, plot_circle)&#60;br /&#62;
%&#60;br /&#62;
% INPUTS:&#60;br /&#62;
%       Nx, Ny          - size of the 2D grid [grid points]&#60;br /&#62;
%       cx, cy          - centre of the circle [grid points], if set&#60;br /&#62;
%                         to 0, the centre of the grid is used&#60;br /&#62;
%       radius          - circle radius [grid points]&#60;br /&#62;
%&#60;br /&#62;
% OPTIONAL INPUTS:&#60;br /&#62;
%       arc_angle       - arc angle for incomplete circle [radians]&#60;br /&#62;
%                         (default = 2*pi)&#60;br /&#62;
%       plot_circle     - Boolean controlling whether the circle is plotted&#60;br /&#62;
%                         using imagesc (default = false)&#60;br /&#62;
%&#60;br /&#62;
% OUTPUTS:&#60;br /&#62;
%       circle          - 2D binary map of a circle&#60;br /&#62;
%&#60;br /&#62;
% ABOUT:&#60;br /&#62;
%       author          - Bradley Treeby&#60;br /&#62;
%       date            - 1st May 2009&#60;br /&#62;
%       last update     - 20th December 2011&#60;br /&#62;
%&#60;br /&#62;
% This function is part of the k-Wave Toolbox (&#60;a href=&#34;http://www.k-wave.org&#34; rel=&#34;nofollow&#34;&#62;http://www.k-wave.org&#60;/a&#62;)&#60;br /&#62;
% Copyright (C) 2009-2012 Bradley Treeby and Ben Cox&#60;br /&#62;
%&#60;br /&#62;
% See also makeCartCircle, makeDisc&#60;/p&#62;
&#60;p&#62;% This file is part of k-Wave. k-Wave is free software: you can&#60;br /&#62;
% redistribute it and/or modify it under the terms of the GNU Lesser&#60;br /&#62;
% General Public License as published by the Free Software Foundation,&#60;br /&#62;
% either version 3 of the License, or (at your option) any later version.&#60;br /&#62;
%&#60;br /&#62;
% k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY&#60;br /&#62;
% WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS&#60;br /&#62;
% FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for&#60;br /&#62;
% more details.&#60;br /&#62;
%&#60;br /&#62;
% You should have received a copy of the GNU Lesser General Public License&#60;br /&#62;
% along with k-Wave. If not, see &#38;lt;http://www.gnu.org/licenses/&#38;gt;.&#60;/p&#62;
&#60;p&#62;% check for plot_circle input&#60;br /&#62;
if nargin &#38;lt; 7&#60;br /&#62;
    plot_circle = false;&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;% check for arc_angle input&#60;br /&#62;
if nargin &#38;lt; 6&#60;br /&#62;
    angle0 = 0;&#60;br /&#62;
    angle1 = 2*pi;&#60;br /&#62;
elseif numel(arc_angle) == 1&#60;br /&#62;
    angle0 = 0;&#60;br /&#62;
    angle1 = arc_angle;&#60;br /&#62;
    if angle1 &#38;gt; 2*pi&#60;br /&#62;
        angle1 = 2*pi;&#60;br /&#62;
    elseif angle1 &#38;lt; 0&#60;br /&#62;
        angle1 = 0;&#60;br /&#62;
    end&#60;br /&#62;
else&#60;br /&#62;
    angle0 = arc_angle(1);&#60;br /&#62;
    angle1 = arc_angle(2);&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;% force integer values&#60;br /&#62;
Nx = round(Nx);&#60;br /&#62;
Ny = round(Ny);&#60;br /&#62;
cx = round(cx);&#60;br /&#62;
cy = round(cy);&#60;br /&#62;
radius = round(radius);&#60;/p&#62;
&#60;p&#62;% check for zero values&#60;br /&#62;
if cx == 0&#60;br /&#62;
    cx = floor(Nx/2) + 1;&#60;br /&#62;
end&#60;br /&#62;
if cy == 0&#60;br /&#62;
    cy = floor(Ny/2) + 1;&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;% check the inputs&#60;br /&#62;
if cx &#38;lt; 1 &#124;&#124; cx &#38;gt; Nx &#124;&#124; cy &#38;lt; 1 &#124;&#124; cy &#38;gt; Ny&#60;br /&#62;
    error('The center of the circle must be within the grid');&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;% define literals&#60;br /&#62;
MAGNITUDE = 1;&#60;/p&#62;
&#60;p&#62;% create empty matrix&#60;br /&#62;
circle = zeros(Nx, Ny);&#60;/p&#62;
&#60;p&#62;% initialise loop variables&#60;br /&#62;
x = 0;&#60;br /&#62;
y = radius;&#60;br /&#62;
d = 1 - radius;&#60;/p&#62;
&#60;p&#62;% draw the first cardinal point&#60;br /&#62;
try&#60;br /&#62;
    circle(cx, cy - y) = MAGNITUDE;&#60;br /&#62;
catch&#60;br /&#62;
    error('The circle must fit within the grid');&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;% draw the remaining cardinal points&#60;br /&#62;
py = [cx, cx+y, cx-y];&#60;br /&#62;
px = [cy+y, cy, cy];&#60;br /&#62;
for point_index = 1:length(py)&#60;/p&#62;
&#60;p&#62;    % check whether the point is within the arc made by arc_angle&#60;br /&#62;
    if (atan2(py(point_index) - cx, px(point_index) - cy) + pi) &#38;gt;= angle0 &#38;amp;&#38;amp; (atan2(py(point_index) - cx, px(point_index) - cy) + pi) &#38;lt;= angle1&#60;br /&#62;
        circle(py(point_index), px(point_index)) = MAGNITUDE;&#60;br /&#62;
    end&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;% loop through the remaining points using the midpoint circle algorithm&#60;br /&#62;
while ( x &#38;lt; y - 1 )&#60;/p&#62;
&#60;p&#62;    x = x + 1;&#60;br /&#62;
    if ( d &#38;lt; 0 )&#60;br /&#62;
        d = d + x + x + 1;&#60;br /&#62;
    else&#60;br /&#62;
        y = y - 1;&#60;br /&#62;
        a = x - y + 1;&#60;br /&#62;
        d = d + a + a;&#60;br /&#62;
    end&#60;/p&#62;
&#60;p&#62;    % setup point indices&#60;br /&#62;
    py = [x+cx, y+cx, y+cx, x+cx, -x+cx, -y+cx, -y+cx, -x+cx];&#60;br /&#62;
    px = [y+cy, x+cy, -x+cy, -y+cy, -y+cy, -x+cy, x+cy, y+cy];&#60;/p&#62;
&#60;p&#62;    % loop through each point&#60;br /&#62;
    for point_index = 1:length(py)&#60;/p&#62;
&#60;p&#62;        % check whether the point is within the arc made by arc_angle&#60;br /&#62;
        if (atan2(py(point_index) - cx, px(point_index) - cy) + pi) &#38;gt;= angle0 &#38;amp;&#38;amp; (atan2(py(point_index) - cx, px(point_index) - cy) + pi) &#38;lt;= angle1&#60;br /&#62;
            circle(py(point_index), px(point_index)) = MAGNITUDE;&#60;br /&#62;
        end&#60;br /&#62;
    end&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;% create the figure&#60;br /&#62;
if plot_circle&#60;br /&#62;
    figure;&#60;br /&#62;
    imagesc(circle, [-1 1]);&#60;br /&#62;
    colormap(getColorMap);&#60;br /&#62;
    axis image;&#60;br /&#62;
    xlabel('y-position [grid points]');&#60;br /&#62;
    ylabel('x-position [grid points]');&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;Hope they could be useful.&#60;/p&#62;
&#60;p&#62;Chao
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
