[SOLVED]Again with arrow head, QTransform.
-
Hello,
Here is my arrow head, a rhomb:
!http://dl.dropbox.com/u/21063554/Rhomb.png(Rhomb)!
@
QPolygonF arrowHead;
arrowHead.push_back(QPointF(0,0));
arrowHead.push_back(QPointF(arrowHead.first().x() + 5, arrowHead.first().y() - 5));
arrowHead.push_back(QPointF(arrowHead.first().x(), arrowHead.first().y() - 10));
arrowHead.push_back(QPointF(arrowHead.first().x() - 5, arrowHead.first().y() - 5));
arrowHead.push_back(arrowHead.first());
@With QTransform::translate we replace QPointF(0, 0) with (intersectPoint.x(), intersectPoint.y()) and with QTransform::rotate we rotate the rhomb to the line angle (centerLine.angle() + 90). But when I am rotating the line, the rhomb rotates in the opposite of my line angle.
@
QTransform transform = QTransform().translate(intersectPoint.x(), intersectPoint.y()).rotate(centerLine.angle() + 90, Qt::ZAxis);
@So, I tried this piece of code, and works, the rhomb angle is the same angle that line angle. But the rhomb is located at Point(0, 0).
@
QTransform transform = QTransform().rotate(centerLine.angle() + 90, Qt::ZAxis).inverted();
@Finally, two codes below do not work, both the angle and position is inconsistent. I think that the only must be inverted() is the angle and not the QTransform at all.
@
QTransform transform = QTransform().translate(intersectPoint.x(), intersectPoint.y()).rotate(centerLine.angle() + 90, Qt::ZAxis).inverted();
@
@
QTransform transform = QTransform().rotate(centerLine.angle() + 90, Qt::ZAxis).inverted();
transform = transform.translate(intersectPoint.x(), intersectPoint.y());
@Thanks, Mario.
-
I apologize, after I wrote above post, I realized that I must invert/normalize the angle by myself. I don't know why inverted() function inverted all QTransform, so below is the final (or part of) code:
@
QLineF centerLine = this->centerLine();
qreal angle = centerLine.angle();if (centerLine.dy() >= 0 || centerLine.dy() <= 0) {
angle = -angle;
}QPolygonF arrowHead;
arrowHead.push_back(QPointF(0,0));
arrowHead.push_back(QPointF(arrowHead.first().x() + 5, arrowHead.first().y() - 5));
arrowHead.push_back(QPointF(arrowHead.first().x(), arrowHead.first().y() - 10));
arrowHead.push_back(QPointF(arrowHead.first().x() - 5, arrowHead.first().y() - 5));
arrowHead.push_back(arrowHead.first());QTransform transform = QTransform().translate(intersectPoint.x(), intersectPoint.y()).rotate(angle - 90, Qt::ZAxis);
QPolygonF transformed = transform.map(arrowHead);
@
Note at the 15 line we subtract 90 to angle (angle - 90).Now we can add any types of arrow heads:
@
QPolygonF arrowHead;
arrowHead.push_back(QPointF(0,0));
arrowHead.push_back(QPointF(arrowHead.first().x() + 5, arrowHead.first().y() - 5));
//arrowHead.push_back(QPointF(arrowHead.first().x(), arrowHead.first().y() - 10));
arrowHead.push_back(arrowHead.first());
arrowHead.push_back(QPointF(arrowHead.first().x() - 5, arrowHead.first().y() - 5));
arrowHead.push_back(arrowHead.first());
@@
QPolygonF arrowHead;
arrowHead.push_back(QPointF(0,0));
arrowHead.push_back(QPointF(arrowHead.first().x() + 5, arrowHead.first().y() - 5));
//arrowHead.push_back(QPointF(arrowHead.first().x(), arrowHead.first().y() - 10));
//arrowHead.push_back(arrowHead.first());
arrowHead.push_back(QPointF(arrowHead.first().x() - 5, arrowHead.first().y() - 5));
arrowHead.push_back(arrowHead.first());
@.....
Thanks, Mario.