[Solved] positioning pie slice problems


I’ve revamped this and created a method out of it. I did the following to fix my issue. Firstly, I got rid of the process that converted the beginning and ending angles from degree to radians by creating another function that does converts just the ending angle to radians. After Circular_arc is called, I set start_angle equal to the value of end_angle. Less code is written/used. Secondly, I removed the first calculation for finding x,y and moved the second one to the first thing in the loop. This wasn’t a necessity, but I’m a big fan of writing as little code as possible. I’m lazy like that. The third biggest part and the whole reason for the OP in the first place was starting the current arc and the end of the previous arc. To do this, I created a variable and set it equal to the value of the start_angle. I then set parameters in the do-while loop to while (start_angle <= (end_angle+angle)). This started the current arc at the end of the previous arc.

The following is my attempt at converting my code to C++. If there are errors then please let me know and I’ll do my best fix them. I hope this helps someone in the future!

...
void Circular_arc(constint h, constint k, constint r, constint start_angle, constint end_angle)
{
    float angle
    angle = start_angle
    do
    {

        x = (r*cos(start_angle));
        y = (r*sin(start_angle));

        putpixel((int)(h + x + 0.5), (int)(k - y + 0.5), getcolor());

        angle += 0.001;


    } while (start_angle <= (end_angle+angle));
}
...

Here’s what the pie chart looks like so far…

enter image description here

solved positioning pie slice problems