Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Code to Figure out x,y cords for CDC::Pie inside an CDC::Ellipse given %

Code to Figure out x,y cords for CDC::Pie inside an CDC::Ellipse given %

Scheduled Pinned Locked Moved C / C++ / MFC
graphics
3 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    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
    
    Mircea NeacsuM 1 Reply Last reply
    0
    • F ForNow

      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
      
      Mircea NeacsuM Offline
      Mircea NeacsuM Offline
      Mircea Neacsu
      wrote on last edited by
      #2

      Try this:

      angle = percent / 50 * PI

      Mircea

      F 1 Reply Last reply
      0
      • Mircea NeacsuM Mircea Neacsu

        Try this:

        angle = percent / 50 * PI

        Mircea

        F Offline
        F Offline
        ForNow
        wrote on last edited by
        #3

        or I think I can divide the radius rect.right - rect.lef2 / 2 thank it worked

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups