【发布时间】:2016-05-24 13:01:02
【问题描述】:
我已经为指针定义了一个多边形:
0,-12,10,12,-10,12
这个多边形的质心是:
0,0
我想围绕质心旋转多边形,这样 45 度会使指针指向 2 点钟方向,180 度会使指针指向 6 点钟方向,270 到 9 点钟方向。
我是用 Qt5.6 写的,到目前为止我的代码看起来是这样的,我知道它不正确:
QStringList lstPoints = strPoints.split(clsXMLnode::mcucPointsDelimiter);
int intPoints = lstPoints.length();
if ( intPoints >= 2 ) {
int intArraySize = intPoints / 2;
QPoint aryPts[intArraySize], ptXY = pobjChild->ptGetXY();
int i, p;
i = p = 0;
while( p<intPoints ) {
float fltX = lstPoints[p++].toFloat()
,fltY = lstPoints[p++].toFloat();
if ( fltAngle != 0.0f ) {
double dblRadians = (fltAngle / 180.0) * M_PI
,dblCosAngle = cos(dblRadians)
,dblSinAngle = sin(dblRadians);
fltX = fltX * dblCosAngle - fltY * dblSinAngle;
fltY = fltY * dblSinAngle + fltX * dblCosAngle;
}
//Translate local co-ordinates to co-ordinates to be used on display
fltX += (float)ptXY.x();
fltY += (float)ptXY.y();
aryPts[i++] = QPoint((int)fltX, (int)fltY);
}
if ( strColor.isEmpty() != true ) {
pobjPainter->setPen(QColor(strColor));
}
if ( strFill.isEmpty() != true ) {
pobjPainter->setBrush(QBrush(QColor(strFill)));
}
pobjPainter->drawPolygon(aryPts, intArraySize, Qt::WindingFill);
strPoints 是一个字符串,包含由 ',' 分隔的多边形。
如果没有旋转 (0),多边形会出现在我期望的位置,但任何旋转它仍然会出现在我期望的位置,但看起来不正确。
【问题讨论】: