So, I'm in my third semester of Algebra, hopefully my last, and we're dealing a lot with circles and ellipses. Every time I'm dealing with these, I always notice how different they look from every circle and ellipse drawing algorithm I've seen. Because of this, I thought I might post here a bit about how to draw an ellipse using algebra. It's pretty simple.
The equation for an ellipse is this:
(x-centerx)^2 (y-centery)^2
---------- + -----------
(width/2)^2 (height/2)^2
Here's the more boring formal version, ignore the stuff in the image below the top equation:
So, if you loop over an area, this equation will yield different values:
0 = The center of the circle
<1 = inside the circle
1 = The exact edge of the circle
>1 = The outside of the circle
The easy way to draw a circle is to loop in a square from x-(width/2) and y-(height/2) to x+(width/2) and y+(height/2). You can of course loop over more area or less depending on how you set up your if statement. Next, you'll calculate your circle's value for the given x and y, which will be in the range above. Then, you'll use this in an if statement depending on how you want to draw your circle. Here's an example in C using pdcurses:
int i,j;
float width,height,CenterX,CenterY;
float Circle;
width=20;
height=10;
CenterX=40;
CenterY=12;
clear();
for(i=0;i<80;i++)
for(j=0;j<25;j++)
{
Circle = (((i-CenterX)*(i-CenterX))/((width/2)*(width/2)))+((((j-CenterY)*(j-CenterY))/((height/2)*(height/2))));
if(Circle>0&&Circle<1.1f)
mvprintw(j,i,"#");
};
refresh();
getch();
//Easy huh?