image thumbnail
from Ellipse generation by Chandan
Generation of ellipse using Midpoint ellipse algorithm

ellipse()
% AUTHOR    :CHANDAN KUMAR 
% TITLE     :MIDPOiNT ELLIPSE ALGORITHM
% SUBJECT   :COMPUTER GRAPHICS AND SOLID MODELLING
% DISCLAIMER:

function ellipse()
clc,clear all
c = input('Give the centre coord[x,y]: ');   %INTERACTIVE INPUT OF CENTRE AND RADIUS 
a = input('Give the value of major/minor axis[a,b]: ');
x = 0;
y = a(2);
p1= a(2)*a(2) - a(1)*a(1)*a(2) + 0.25*a(1)*a(1);
p2 = a(2)*a(2)*(x + 0.5)*(x+0.5) + a(1)*a(1)*(y-1)*(y-1) - a(1)*a(1)*a(2)*a(2);
while (a(2)*a(2)*x) < (a(1)*a(1)*y)
    for i= -1:2:1
        for j= -1:2:1
            plot(c(1)+i*x,c(2)+j*y,'r.');
            hold on
        end
    end
    if(p1<0)
		p1 = p1 + 2*a(2)*a(2)*x + 3*a(2)*a(2);
		x = x+1;
	else
	    p1 = p1 - 2*a(1)*a(1)*y + 2*a(2)*a(2)*x + 2*a(1)*a(1) + 3*a(2)*a(2);
	    x = x + 1;
	    y = y - 1;
	 end
end
while y > 0
    for i= -1:2:1
        for j= -1:2:1
            plot(c(1)+i*x,c(2)+j*y,'r.');
        end
    end
    if(p2 < 0)
		p2 = p2 + 2*a(2)*a(2)*x  - 2*a(1)*a(1)*y +  3*a(1)*a(1) + 2*a(2)*a(2);
		x = x + 1;
		y = y - 1;
	else
	    p1 = p1 - 2*a(1)*a(1)*y +  3*a(1)*a(1);
	    y = y - 1;
	 end
end
grid on , axis square
axis([c(1)-a(1)-5 c(1)+a(1)+5 c(2)-a(2)-5 c(2)+a(2)+5]); 
title('Ellipse generation by Midpoint generation algorithm')

Contact us at files@mathworks.com