一直没弄出的小问题,GDI+相关,绘制弧线

j8daxue j8daxue 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
为了做出一个现实百分比的饼图,需要绘一个饼图和若干小扇形来实现。扇形则表示所占的百分比。
部分代码:


//draw small parts
int xCenter = m_rcArea.X + m_rcArea.Width / 2;
int yCenter = m_rcArea.Y + m_rcArea.Height / 2;
int B = m_rcArea.Height / 2;
int A = m_rcArea.Width / 2;
PointF lastPt((REAL)A,0);
REAL lastAngel = 0; //上次累加的角度
REAL angel = 0; //本次角度
REAL totalPer = 0; //累加百分比
REAL totalRadians = 0; //累加弧度
//m_vecUNIT只有一个值和颜色信息
for (unsigned int i = 0 ; i < m_vecUNIT.size() ; ++i)
{
//m_dTotal是整个饼图的值
angel = m_vecUNIT[i]->dPercent * 360 / m_dTotal;
totalPer += m_vecUNIT[i]->dPercent;
if (totalPer >= m_dTotal)
{
return ;
}
totalRadians = totalPer * 2 * PIE / m_dTotal ;

path1.Reset();

path1.AddLine((REAL)xCenter,(REAL)yCenter,(REAL)lastPt.X + (REAL)xCenter,(REAL)lastPt.Y + (REAL)yCenter);
path1.AddArc(m_rcArea,lastAngel, angel);

float endX = (REAL)A * cos(totalRadians) + (REAL)xCenter;
float endY = (REAL)B * sin(totalRadians) + (REAL)yCenter;
path1.AddLine((REAL)A * cos(totalRadians) + (REAL)xCenter,(REAL)B * sin(totalRadians) + (REAL)yCenter,(REAL)xCenter,(REAL)yCenter);


path1.CloseAllFigures();
g.DrawPath(&Pen(m_vecUNIT[i]->crContent),&path1);

BYTE crR = m_vecUNIT[i]->crContent.GetR();
BYTE crG = m_vecUNIT[i]->crContent.GetG();
BYTE crB = m_vecUNIT[i]->crContent.GetB();

// g.FillPath(&LinearGradientBrush(m_rcArea,Color(128,crR,crG ,crB ),Color(255,crR ,crG ,crB ),270,LinearGradientModeBackwardDiagonal),&path1);

lastPt.X = A * cos(totalRadians) ;
lastPt.Y = B * sin(totalRadians) ;
lastAngel = totalPer * 360 / m_dTotal;
}

然后发现所加入的AddArc终点和计算的终点一直不重合。调试了一个下午,发现sin和cos所算的值似乎没问题,但AddArc为什么就是不重合?

...全文

相关推荐

评论 15
收藏 已收藏
分享
返回顶部
j8daxue
VC/MFC 16,550 成员 421,606 内容