What's the best way to draw an arc using graphics.library, given two angles in degrees which depict the starting and ending angle of the arc from the horizontal?
I came up with this unoptimised monstrosity, which unsurprisingly doesn't work:
void arc_gfxlib(int x, int y, int radius, int angle1, int angle2, int quarter)
{
double angle1_r = angle1 * (M_PI / 180.0);
double angle2_r = angle1 * (M_PI / 180.0);
double angle, b, c;
double step = (angle2_r - angle1_r) / ((angle2_r - angle1_r) * (double)radius);
int x0, y0, x1, y1;
switch(quarter) {
case 1:
x0 = x;
y0 = y;
break;
case 2:
x0 = -x;
y0 = y;
break;
case 3:
x0 = -x;
y0 = -y;
break;
case 4:
x0 = x;
y0 = -y;
break;
}
b = angle1_r;
c = angle2_r;
for(angle = b; angle <= c; angle += step) {
x1 = (int)(cos(angle) * (double)radius);
y1 = (int)(sin(angle) * (double)radius);
WritePixel(rp, x0 + x1, y0 + y1);
}
}
void arc(int x, int y, int radius, int angle1, int angle2)
{
int a1, a2;
a1 = angle1;
if(angle1 <= 90) {
if(angle2 > 90) a2 = 90;
else a2 = angle2;
arc_gfxlib(x, y, radius, a1, a2, 1);
a1 = 90;
}
if(angle1 <= 180) {
if(angle2 > 180) a2 = 180;
else a2 = angle2;
if((angle2 > 90) && angle2 <= 180)
arc_gfxlib(x, y, radius, a1, a2, 2);
a1 = 180;
}
if(angle1 <= 270) {
if(angle2 > 270) a2 = 270;
else a2 = angle2;
if((angle2 > 180) && angle2 <= 270)
arc_gfxlib(x, y, radius, a1, a2, 3);
a1 = 270;
}
if(angle2 > 270) {
arc_gfxlib(x, y, radius, a1, angle2, 4);
}
}