I have to create an algorithm to produce a circular segment, so I have to give the radius, the center, and the initial and final angle.
I have been working on the midpoint circle algorithm but I don know how to change it to produce a circular segment.
int xc;
int yc;
int r;
private color colorC;
Circulo2(int x, int y, int ra) {
xc=x;
yc=y;
r=ra;
colorC=color(0,0,0);
}
void dibujar(int xc,int yc,int x,int y){
int X= xc+x;
int Y= yc+y;
pixels[X+Ywidth]=colorC;
X= xc-x;
Y= yc+y;
pixels[X+Ywidth]=colorC;
X= xc+x;
Y= yc-y;
pixels[X+Ywidth]=colorC;
X= xc-x;
Y= yc-y;
pixels[X+Ywidth]=colorC;
X= xc+y;
Y= yc+x;
pixels[X+Ywidth]=colorC;
X= xc-y;
Y= yc+x;
pixels[X+Ywidth]=colorC;
X= xc+y;
Y= yc-x;
pixels[X+Ywidth]=colorC;
X= xc-y;
Y= yc-x;
pixels[X+Ywidth]=colorC;
}
void circ(int xc, int yc, int r){
loadPixels();
int x,y,z;
x=0;
y=r;
z=1-r;
dibujar(xc,yc,x,y);
while(x<y){
x+=1;
if(z<0){
z=z+2x+3;
}else{
y-=1;
z=z+2(x-y)+5;
}
dibujar(xc,yc,x,y);
}
updatePixels();
}
I would appreciate it if you can help me