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. Rotated line item in a scene along its center point
Forum Updated to NodeBB v4.3 + New Features

Rotated line item in a scene along its center point

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 2 Posters 6.8k 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.
  • mrjjM mrjj

    @AlvaroS said:
    Super :)

    To go the other way cant u just make it negative ?
    setRotation( -angle);

    AlvaroSA Offline
    AlvaroSA Offline
    AlvaroS
    wrote on last edited by
    #6

    @mrjj Yes thanks!!!! I mark as solved :)))

    1 Reply Last reply
    1
    • mrjjM mrjj

      @AlvaroS said:
      Super :)

      To go the other way cant u just make it negative ?
      setRotation( -angle);

      AlvaroSA Offline
      AlvaroSA Offline
      AlvaroS
      wrote on last edited by
      #7

      @mrjj just a question my friend.
      I realize that If I rotate the line, the x1,x2,y1,y2 parameters of line do not change. Is it true? Maybe I have to calculate and then setline?

      mrjjM 1 Reply Last reply
      0
      • AlvaroSA AlvaroS

        @mrjj just a question my friend.
        I realize that If I rotate the line, the x1,x2,y1,y2 parameters of line do not change. Is it true? Maybe I have to calculate and then setline?

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #8

        @AlvaroS
        I have not tested it
        but I would assume you apply a transformation
        to the Line so the points stay the same
        but its projected to scene as rotated.

        AlvaroSA 1 Reply Last reply
        0
        • mrjjM mrjj

          @AlvaroS
          I have not tested it
          but I would assume you apply a transformation
          to the Line so the points stay the same
          but its projected to scene as rotated.

          AlvaroSA Offline
          AlvaroSA Offline
          AlvaroS
          wrote on last edited by
          #9

          @mrjj Yes It works like that. So i try to calculate the point rotated and then setLine!!

          mrjjM 1 Reply Last reply
          0
          • AlvaroSA AlvaroS

            @mrjj Yes It works like that. So i try to calculate the point rotated and then setLine!!

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #10

            @AlvaroS

            Well yes, they seem to use setLine here
            http://www.mzan.com/article/22285697-qt-algorithm-to-rotate-and-resize-a-qgraphicslineitem-present-on-a-qgraphicssce.shtml

            AlvaroSA 1 Reply Last reply
            0
            • mrjjM mrjj

              @AlvaroS

              Well yes, they seem to use setLine here
              http://www.mzan.com/article/22285697-qt-algorithm-to-rotate-and-resize-a-qgraphicslineitem-present-on-a-qgraphicssce.shtml

              AlvaroSA Offline
              AlvaroSA Offline
              AlvaroS
              wrote on last edited by
              #11

              @mrjj Good morning friend.
              I trie to use setLine like that:

                      line_rotated->setTransformOriginPoint(line_rotated->boundingRect().center()); //Rotated line along center line.
                      line_rotated->setRotation(-ui->Degrees_to_Rotate->text().toDouble()); //Set counterclockwise rotation in degrees (counterclockwise=negative)
                      QLineF newline= line_rotated->line();
                      line_rotated->setLine(newline);
                      line_rotated ->setFlag(QGraphicsItem::ItemIsSelectable, true); // Every items can be selected
                      line_rotated->setSelected(true);
                      line_rotated ->setCursor(Qt::PointingHandCursor); // When the cursor is on a line item it change to a hand cursor instead of a tipical arrow.
              

              In this code, line is rotated in the scene but its point does not change...

              So tried this next code:

                      line_rotated->setTransformOriginPoint(line_rotated->boundingRect().center()); //Rotated line along center line.
                      line_rotated->setRotation(-ui->Degrees_to_Rotate->text().toDouble()); //Set counterclockwise rotation in degrees (counterclockwise=negative)
                      QLineF newline= line_rotated->line();
                      newline.setAngle(0); //To change the line points
                      line_rotated->setLine(newline);
                      line_rotated ->setFlag(QGraphicsItem::ItemIsSelectable, true); // Every items can be selected
                      line_rotated->setSelected(true);
                      line_rotated ->setCursor(Qt::PointingHandCursor); // When the cursor is on a line item it change to a hand cursor instead of a tipical arrow.
              
              

              So in this case, the line change its point and is rotated, but it is rotated along its second point, not along its center point...

              Could you help me to do that using setLine¿

              Thanks a lot!

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #12

                @AlvaroS said:

                Hi
                The docs says it change second point
                so its normal for it to use first point as center.
                I dont think u can change that.
                http://doc.qt.io/qt-5/qlinef.html#setAngle

                AlvaroSA 1 Reply Last reply
                0
                • mrjjM mrjj

                  @AlvaroS said:

                  Hi
                  The docs says it change second point
                  so its normal for it to use first point as center.
                  I dont think u can change that.
                  http://doc.qt.io/qt-5/qlinef.html#setAngle

                  AlvaroSA Offline
                  AlvaroSA Offline
                  AlvaroS
                  wrote on last edited by
                  #13

                  @mrjj So I can not use setLine for doing that. It is rare that with

                          line_rotated->setTransformOriginPoint(line_rotated->boundingRect().center()); //Rotated line along center line.
                          line_rotated->setRotation(-ui->Degrees_to_Rotate->text().toDouble()); //Set counterclockwise rotation in degrees (counterclockwise=negative)
                         ```
                  
                  The line rotated how I want but the points line does not change..
                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #14

                    Well if you want to rotate the line around center and rotate the actual points then
                    you have to calculate the x,y yourself using the center as base.

                    POINT rotate_point(float cx,float cy,float angle,POINT p)
                    {
                      float s = sin(angle);
                      float c = cos(angle);
                    
                      // translate point back to origin:
                      p.x -= cx;
                      p.y -= cy;
                    
                      // rotate point
                      float xnew = p.x * c - p.y * s;
                      float ynew = p.x * s + p.y * c;
                    
                      // translate point back:
                      p.x = xnew + cx;
                      p.y = ynew + cy;
                      return p;
                    }
                    

                    http://stackoverflow.com/questions/2259476/rotating-a-point-about-another-point-2d

                    Disclaimer: There might be a way to apply the rotate transformation and then
                    get modified points in some more easy way but I dont know it.

                    AlvaroSA 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      Well if you want to rotate the line around center and rotate the actual points then
                      you have to calculate the x,y yourself using the center as base.

                      POINT rotate_point(float cx,float cy,float angle,POINT p)
                      {
                        float s = sin(angle);
                        float c = cos(angle);
                      
                        // translate point back to origin:
                        p.x -= cx;
                        p.y -= cy;
                      
                        // rotate point
                        float xnew = p.x * c - p.y * s;
                        float ynew = p.x * s + p.y * c;
                      
                        // translate point back:
                        p.x = xnew + cx;
                        p.y = ynew + cy;
                        return p;
                      }
                      

                      http://stackoverflow.com/questions/2259476/rotating-a-point-about-another-point-2d

                      Disclaimer: There might be a way to apply the rotate transformation and then
                      get modified points in some more easy way but I dont know it.

                      AlvaroSA Offline
                      AlvaroSA Offline
                      AlvaroS
                      wrote on last edited by
                      #15

                      @mrjj Yes!! Now I got it!
                      I just had to rotate point start and point end along center point using these equations. so now it works!!
                      Thanks a lot!

                      mrjjM 1 Reply Last reply
                      1
                      • AlvaroSA AlvaroS

                        @mrjj Yes!! Now I got it!
                        I just had to rotate point start and point end along center point using these equations. so now it works!!
                        Thanks a lot!

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #16

                        @AlvaroS
                        Super. Good work :)
                        If possible please mark as solved.

                        AlvaroSA 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @AlvaroS
                          Super. Good work :)
                          If possible please mark as solved.

                          AlvaroSA Offline
                          AlvaroSA Offline
                          AlvaroS
                          wrote on last edited by
                          #17

                          @mrjj Yes! It is marked as solved :)!! Thanks again!

                          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