Code to Figure out x,y cords for CDC::Pie inside an CDC::Ellipse given %
-
hi Below is the code I have for Drawing a Pie give a percentage thing is it looks nice and I traced a percent of 10.000 however calculation of x & y are negative and it ends up (the pie) being on the left side of the circle Wondering if I am doing anything wrong after getting to 2 CPoints and I do a CDC:Pie
CPie::CPie(double percentage, PieWnd *pieptr)
{piecalc(pieptr->currpercent, &piepointstart, pieptr); piecalc(percentage, &piepointend, pieptr); pieptr->currpercent = percentage; /\* get corinates for title \*/
}
CPoint *CPie::piecalc(double percent, CPoint *firstpt, PieWnd *pieptr)
{double PI = 3.1415926535897931; double angle = percent / 100; angle = angle \* 360;
// angle = angle * PI / 180;
CRect pierect; double radius = pieptr->ellipserect.Height() / 2; // radius = radius \* 3.0 / 5.0; double offx = (radius \* sin(angle)); double offy = (radius \* cos(angle)); double origx = (pieptr->ellipserect.right + pieptr->ellipserect.left) / 2; double origy = (pieptr->ellipserect.top + pieptr->ellipserect.bottom) / 2; firstpt->x = origx + offx; firstpt->y = origy + offx; /\* multiple angle by pie \*/ return firstp
-
hi Below is the code I have for Drawing a Pie give a percentage thing is it looks nice and I traced a percent of 10.000 however calculation of x & y are negative and it ends up (the pie) being on the left side of the circle Wondering if I am doing anything wrong after getting to 2 CPoints and I do a CDC:Pie
CPie::CPie(double percentage, PieWnd *pieptr)
{piecalc(pieptr->currpercent, &piepointstart, pieptr); piecalc(percentage, &piepointend, pieptr); pieptr->currpercent = percentage; /\* get corinates for title \*/
}
CPoint *CPie::piecalc(double percent, CPoint *firstpt, PieWnd *pieptr)
{double PI = 3.1415926535897931; double angle = percent / 100; angle = angle \* 360;
// angle = angle * PI / 180;
CRect pierect; double radius = pieptr->ellipserect.Height() / 2; // radius = radius \* 3.0 / 5.0; double offx = (radius \* sin(angle)); double offy = (radius \* cos(angle)); double origx = (pieptr->ellipserect.right + pieptr->ellipserect.left) / 2; double origy = (pieptr->ellipserect.top + pieptr->ellipserect.bottom) / 2; firstpt->x = origx + offx; firstpt->y = origy + offx; /\* multiple angle by pie \*/ return firstp
Try this:
angle = percent / 50 * PI
Mircea
-
Try this:
angle = percent / 50 * PI
Mircea