Algorithm of an arc based on the midpoint algorithm

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+Y
width]=colorC;
X= xc+x;
Y= yc-y;
pixels[X+Ywidth]=colorC;
X= xc-x;
Y= yc-y;
pixels[X+Y
width]=colorC;
X= xc+y;
Y= yc+x;
pixels[X+Ywidth]=colorC;
X= xc-y;
Y= yc+x;
pixels[X+Y
width]=colorC;
X= xc+y;
Y= yc-x;
pixels[X+Ywidth]=colorC;
X= xc-y;
Y= yc-x;
pixels[X+Y
width]=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

Hello,

Please format your code:
https://discourse.processing.org/faq#format-your-code

:)

Is this a homework question?

I would start here:

That should be straightforward to implement.

Consider doing this with just point() on the canvas and then adapt it to you pixel [] array

References:
Images and Pixels \ Processing.org
point() \ Language (API) \ Processing 3+

:)

1 Like