Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]Again with arrow head, QTransform.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Again with arrow head, QTransform.

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MaQzma
    wrote on last edited by
    #1

    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.

    Mario.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MaQzma
      wrote on last edited by
      #2

      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.

      Mario.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved