[code]import java.awt.image.BufferedImage;
public class Elipse {
private int x0,y0,a,b;
public Elipse(int x0, int y0, int a, int b){
this.a = a;
this.b = b;
this.x0 = x0;
this.y0 = y0;
}
public void desenhar(int cor, BufferedImage img){
int a2 = a * a; int b2 = b * b;
int twoa2 = 2 * a2; int twob2 = 2 * b2;
int x = 0; int y = b;
int px = 0; int py = twoa2 * y;
double p;
int cont = 0;
desenha_pontos (x0, y0, x, y, cor,img);
p = (int)(b2 - (a2 * b) + (0.25 * a2) + 0.5);
while (px < py) {
x++;
px += twob2;
if (p < 0){
p += b2 + px;
}
else {
y--;
py -= twoa2;
p += b2 + px - py;
}
desenha_pontos (x0, y0, x, y, cor,img);
}
p = (int)(b2 * (x+0.5)*(x+0.5) + a2 * (y-1)*(y-1) - a2 * b2 +0.5);
while (y > 0) {
y--;
py -= twoa2;
if (p > 0) p += a2 - py;
else {
x++;
px += twob2;
p += a2 - py + px;
}
desenha_pontos (x0, y0, x, y, cor,img);
}
}
private void desenha_pontos(int x0, int y0, int x, int y, int value,BufferedImage img)
{
img.setRGB (x0+x,y0+y, value);
if (x0 >= x){
img.setRGB (x0-x,y0+y, value);
}
if (y0 >= y){
img.setRGB (x0+x, y0-y, value);
}
if ((x0 >= x) && (y0 >= y)){
img.setRGB (x0-x, y0-y, value);
}
}
}[/code]
Não sei se vc está trabalhando com BufferedImage, eu usei esta classe para fazer o meu trabalho de CG de primitivas 2D.
Espero q tenha ajudado
Se tiver alguma dúvida no código me pergunte!