June 3, 2012

Mariø™ Mariø™
Hobby Entomologist
43 posts

[SOLVED]Again with arrow head, QTransform.

 

Hello,

Here is my arrow head, a rhomb:
Rhomb

  1. QPolygonF arrowHead;
  2. arrowHead.push_back(QPointF(0,0));
  3. arrowHead.push_back(QPointF(arrowHead.first().x() + 5, arrowHead.first().y() - 5));
  4. arrowHead.push_back(QPointF(arrowHead.first().x(), arrowHead.first().y() - 10));
  5. arrowHead.push_back(QPointF(arrowHead.first().x() - 5, arrowHead.first().y() - 5));
  6. 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.

  1. 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).

  1. 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.

  1. QTransform transform = QTransform().translate(intersectPoint.x(), intersectPoint.y()).rotate(centerLine.angle() + 90, Qt::ZAxis).inverted();

  1. QTransform transform = QTransform().rotate(centerLine.angle() + 90, Qt::ZAxis).inverted();
  2. transform = transform.translate(intersectPoint.x(), intersectPoint.y());

Thanks, Mario.

 Signature 

To be something. You need to do something.

1 reply

June 4, 2012

Mariø™ Mariø™
Hobby Entomologist
43 posts

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:

  1. QLineF centerLine = this->centerLine();
  2. qreal angle = centerLine.angle();
  3.  
  4. if (centerLine.dy() >= 0 || centerLine.dy() <= 0) {
  5.     angle = -angle;
  6. }
  7.  
  8. QPolygonF arrowHead;
  9. arrowHead.push_back(QPointF(0,0));
  10. arrowHead.push_back(QPointF(arrowHead.first().x() + 5, arrowHead.first().y() - 5));
  11. arrowHead.push_back(QPointF(arrowHead.first().x(), arrowHead.first().y() - 10));
  12. arrowHead.push_back(QPointF(arrowHead.first().x() - 5, arrowHead.first().y() - 5));
  13. arrowHead.push_back(arrowHead.first());
  14.  
  15. QTransform transform = QTransform().translate(intersectPoint.x(), intersectPoint.y()).rotate(angle - 90, Qt::ZAxis);
  16.  
  17. 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:

  1. QPolygonF arrowHead;
  2. arrowHead.push_back(QPointF(0,0));
  3. arrowHead.push_back(QPointF(arrowHead.first().x() + 5, arrowHead.first().y() - 5));
  4. //arrowHead.push_back(QPointF(arrowHead.first().x(), arrowHead.first().y() - 10));
  5. arrowHead.push_back(arrowHead.first());
  6. arrowHead.push_back(QPointF(arrowHead.first().x() - 5, arrowHead.first().y() - 5));
  7. arrowHead.push_back(arrowHead.first());

  1. QPolygonF arrowHead;
  2. arrowHead.push_back(QPointF(0,0));
  3. arrowHead.push_back(QPointF(arrowHead.first().x() + 5, arrowHead.first().y() - 5));
  4. //arrowHead.push_back(QPointF(arrowHead.first().x(), arrowHead.first().y() - 10));
  5. //arrowHead.push_back(arrowHead.first());
  6. arrowHead.push_back(QPointF(arrowHead.first().x() - 5, arrowHead.first().y() - 5));
  7. arrowHead.push_back(arrowHead.first());

…..

Thanks, Mario.

 Signature 

To be something. You need to do something.

 
  ‹‹ [Solved] StyleSheet with absolute path      QNetworkAccessManager: How to enable cookies / How to Facebook login? ››

You must log in to post a reply. Not a member yet? Register here!