Code covered by the BSD License  

Highlights from
3 integer algorithms for drawing circles

image thumbnail

3 integer algorithms for drawing circles


Xenya (view profile)


3 implementations of Bresenham and Midpoint algorithm.

figure,subplot(1,3,1),plot(X1,Y1,'g.'),axis equal,title('Midpoint')
subplot(1,3,2),plot(X2,Y2,'r.'),axis equal,title('Bresenham-1')
subplot(1,3,3),plot(X3,Y3,'b.'),axis equal,title('Bresenham-2')

% image example 1
% draw single circle
X_center=70; Y_center=150;
I(sub2ind(size(I),X1+X_center,Y1+Y_center))=1; figure,imshow(I);

% image example 2
% draw a bunch of tiny circles
Sz=500; I=zeros(Sz);
N=25; % # of circles
Cx=round(rand([N 1])*Sz);
Cy=round(rand([N 1])*Sz);

xx = bsxfun(@plus,repmat(X1,[N 1]),Cx); 
yy = bsxfun(@plus,repmat(Y1,[N 1]),Cy); 

% remove points out of range
ii_bad=find(xx<1 | xx>Sz | yy<1 | yy>Sz);
xx(ii_bad)=[]; yy(ii_bad)=[];
I(sub2ind(size(I),xx,yy))=1; figure,imshow(I);

Contact us