画饼图

画饼图要有几个辅助函数:

 

这个函数的功能是把正圆上的角度推算成饼图椭圆上的角度。

int CDlgPie::TransformAngel(CRect rect, int angel)
{

   int nRectWidth = rect.Width();
    
int nRectHeight = rect.Height();
    
double x = nRectWidth * cos(angel * PI / 180);
    
double y = nRectHeight * sin(angel * PI / 180);
    
float result = (float)(atan2(y, x) * 180 / PI);

    
if (result < 0
    
{
        result 
+= 360;
    }


    
int iResult = (int)(result+0.5);
    
return iResult;
}

这个函数是用高中的椭圆公式推出来的,但是我数学比较垃圾,不知道应该怎么简化它了。

CPoint CDlgPie::GetEllipsePoint(CRect rect,  int  angel)
{
    
float a = (float)rect.Width() / 2;
    
float b = (float)rect.Height() / 2;

    angel 
= angel % 360;
    UINT quant 
= angel / 90 + 1;

    
float fAngel = (float)((float)angel / 360 * 2 * PI);
    
float tangent = (float)tan( fAngel );

    
double x = sqrt( a*a*b*/ (b*+ a*a*tangent*tangent) );
    
double y = sqrt( (a*a*b*- b*b*x*x) / a / a );

    
switch ( quant )
    
{
    
case 1:
        
break;
    
case 2:
        x 
= -x;
        
break;
    
case 3:
        x 
= -x;
        y 
= -y;
        
break;
    
case 4:
        y 
= -y;
        
break;
    
default:
        
break;
    }

    x 
= (int)(x+0.5);
    y 
= (int)(y+0.5);
    
    
int nTempX = (int)(a + 0.5);
    
int nTempY = (int)(b + 0.5);

    
int iResultX = (int)x + nTempX + rect.left;
    
int iResultY = abs((int)y - nTempY - rect.top);
    
return CPoint(iResultX, iResultY);
}

 

既然是立体的,就的有阴影的效果。 

long  CDlgPie::GetDimColor( long  lOriginColor)
  {

    // 取得原颜色的RGB值
    long lRed = GetRValue(lOriginColor);
    
long lGreen = GetGValue(lOriginColor);
    long lBlue = GetBValue(lOriginColor);
   
//

    
//

    // 对RGB颜色取半
    long lResultRed = lRed / 2;
    
long lResultGreen = lGreen / 2;
    
long lResultBlue = lBlue / 2;
    
long lResultColor = RGB(lResultRed, lResultGreen, lResultBlue);
    
//

    
return lResultColor;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值