Code covered by the BSD License  

Highlights from
3 integer algorithms for drawing circles

image thumbnail

3 integer algorithms for drawing circles

by

 

3 implementations of Bresenham and Midpoint algorithm.

[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