Code covered by the BSD License  

Highlights from
Three integer algorithms drawing circles

image thumbnail

Three integer algorithms drawing circles

by

 

Midpoint and two versions of Bresenham algorithm for drawing circle.

[X,Y]=bresenham_circle(r,varargin)
% AUTHOR    :CHANDAN KUMAR 
% TITLE     :BRESENHAM CIRCLE ALGORITHM
% SUBJECT   :COMPUTER GRAPHICS AND SOLID MODELLING
% Modified to be a function
function [X,Y]=bresenham_circle(r,varargin)
% function [X,Y]=bresenham_circle(r)
% function [X,Y]=bresenham_circle(r,inc)
% return coordinates of circle points by Bresenham' algo
% center is (0,0)
if nargin==1
    inc =1;
else
    inc=varargin{1};
end    

x = 0;
y = r;
d= 3-2*r;
X=[]; Y=[];
dd=1/inc;
while(x < y)
    X=[X,-x,-y,-x,-y,x,y,x,y];
    Y=[Y,-y,-x, y,x, -y,-x,y,x];
	if d>=0
		d = d +4*(x-y)+10;
		y = y - dd;
	else
		d = d + 4*x +6;
    end 
	x = x + dd;
end














 
 

Contact us