Results 1 to 4 of 4

Thread: the invert of a QTransform's transposed

  1. #1
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question the invert of a QTransform's transposed

    I am trying to save the QGraphicsitem's information in the svg format. I meet a problem about QTransform's invert.
    I transpose a QTransform of QTransform::TxTranslate and invert it. But the result is not correct! I donot know why.
    I upload the source code. Will somebody run the code and give me some hint.
    Attached Files Attached Files
    Last edited by calmspeaker; 13th January 2011 at 05:45.
    Jerry

  2. #2
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: the invert of a QTransform's transposed

    The main.cpp is
    Qt Code:
    1. #include <QtGui>
    2. void showmat(QTransform abc){
    3. qDebug("%s",QString("%1,%2,%3").arg(abc.m11()).arg(abc.m12()).arg(abc.m13()).toLocal8Bit().data());
    4. qDebug("%s",QString("%1,%2,%3").arg(abc.m21()).arg(abc.m22()).arg(abc.m23()).toLocal8Bit().data());
    5. qDebug("%s",QString("%1,%2,%3").arg(abc.m31()).arg(abc.m32()).arg(abc.m33()).toLocal8Bit().data());
    6. }
    7.  
    8. int main()
    9. {
    10. QTransform a(1,0,300,0,1,300,0,0,1);
    11. QTransform temp = QTransform(1,0,0,0,1,0,0,0,1).translate(300,300).transposed();//m_pItem->sceneTransform().transposed();
    12. QTransform temp1 = QTransform(1,0,0,0,1,0,0,0,1).translate(300,300); //m_pItem->sceneTransform();
    13. qDebug("is invertible? %d",temp.isInvertible()?1:0);
    14. qDebug("is equal the made one? %d",temp == a?1:0);
    15.  
    16. qDebug("-----temp------");
    17. showmat(temp);
    18.  
    19.  
    20. QTransform abc = temp.inverted();
    21. qDebug("----temp invert-------");
    22. showmat(abc);
    23.  
    24. qDebug("-----temp1------");
    25. showmat(temp1);
    26.  
    27. qDebug("-----temp1 invert ------");
    28. showmat(temp1.inverted());
    29.  
    30.  
    31.  
    32. qDebug("-----------");
    33. showmat(a);
    34. QTransform a1 = a.inverted();
    35. qDebug("-----------");
    36. showmat(a1);
    37. }
    To copy to clipboard, switch view to plain text mode 
    The result is :
    is invertible? 1
    is equal the made one? 1
    -----temp------
    1,0,300
    0,1,300
    0,0,1
    ----temp invert-------
    1,0,0
    0,1,0
    0,0,1
    -----temp1------
    1,0,0
    0,1,0
    300,300,1
    -----temp1 invert ------
    1,0,0
    0,1,0
    -300,-300,1
    -----------
    1,0,300
    0,1,300
    0,0,1
    -----------
    1,0,-300
    0,1,-300
    0,0,1

    The temp's invert is not correct, why?
    Jerry

  3. #3
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: the invert of a QTransform's transposed

    Just something off-topic : instead of
    Qt Code:
    1. qDebug("%s",QString("%1,%2,%3").arg(abc.m31()).arg(abc.m32()).arg(abc.m33()).toLocal8Bit().data());
    To copy to clipboard, switch view to plain text mode 
    you can write this :
    Qt Code:
    1. qDebug() << abc.m31() << abc.m32() << abc.m33();
    To copy to clipboard, switch view to plain text mode 
    Is a lot more convenient and readable.
    Regards,
    Marc

  4. #4
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: the invert of a QTransform's transposed

    Quote Originally Posted by marcvanriet View Post
    Just something off-topic : instead of
    Qt Code:
    1. qDebug("%s",QString("%1,%2,%3").arg(abc.m31()).arg(abc.m32()).arg(abc.m33()).toLocal8Bit().data());
    To copy to clipboard, switch view to plain text mode 
    you can write this :
    Qt Code:
    1. qDebug() << abc.m31() << abc.m32() << abc.m33();
    To copy to clipboard, switch view to plain text mode 
    Is a lot more convenient and readable.
    Regards,
    Marc
    yes,but must include <QtDebug>.
    Thank you all the same.


    Added after 32 minutes:


    I gave up the transpose method that qt supply and rewrote the code, finnally I got the correct result.
    Qt Code:
    1. #include <QtGui>
    2. void showmat(QTransform abc){
    3. qDebug("%s",QString("%1,%2,%3").arg(abc.m11()).arg(abc.m12()).arg(abc.m13()).toLocal8Bit().data());
    4. qDebug("%s",QString("%1,%2,%3").arg(abc.m21()).arg(abc.m22()).arg(abc.m23()).toLocal8Bit().data());
    5. qDebug("%s",QString("%1,%2,%3").arg(abc.m31()).arg(abc.m32()).arg(abc.m33()).toLocal8Bit().data());
    6. }
    7.  
    8. int main()
    9. {
    10. QTransform a(1,0,300,0,1,300,0,0,1);
    11. //QTransform temp = QTransform(1,0,0,0,1,0,0,0,1).translate(300,300).transposed();//m_pItem->sceneTransform().transposed();
    12. QTransform temp1 = QTransform(1,0,0,0,1,0,0,0,1).translate(300,300); //m_pItem->sceneTransform();
    13. //QTransform temp = temp1.transposed();
    14. QTransform temp(temp1.m11(),temp1.m21(),temp1.m31(),temp1.m12(),temp1.m22(),temp1.m32(),temp1.m13(),temp1.m23(),temp1.m33());
    15. qDebug("is invertible? %d",temp.isInvertible()?1:0);
    16. qDebug("is equal the made one? %d",temp == a?1:0);
    17.  
    18. qDebug("-----temp------");
    19. showmat(temp);
    20. qDebug("temp's Txtype = %d",temp.type());
    21.  
    22.  
    23. QTransform abc = temp.inverted();
    24. qDebug("----temp invert-------");
    25. showmat(abc);
    26.  
    27. qDebug("-----temp1------");
    28. showmat(temp1);
    29.  
    30. qDebug("-----temp1 invert ------");
    31. showmat(temp1.inverted());
    32.  
    33.  
    34.  
    35. qDebug("-----------");
    36. showmat(a);
    37. qDebug("a's Txtype = %d",temp.type());
    38. QTransform a1 = a.inverted();
    39. qDebug("-----------");
    40. showmat(a1);
    41. }
    To copy to clipboard, switch view to plain text mode 
    But I donnot know why!
    Last edited by calmspeaker; 17th January 2011 at 03:19.
    Jerry

Similar Threads

  1. Using QTransform to map the mouse
    By Cruz in forum Qt Programming
    Replies: 0
    Last Post: 22nd February 2010, 08:47
  2. QTransform()
    By mkind in forum Newbie
    Replies: 0
    Last Post: 19th February 2010, 21:45
  3. GraphicsItemChange and QTransform
    By ct-xuyaojun in forum Qt Programming
    Replies: 0
    Last Post: 28th September 2009, 09:16
  4. QTransform + drawLine ?
    By verburg in forum Qt Programming
    Replies: 0
    Last Post: 23rd January 2009, 00:32
  5. QTransform vs QMatrix
    By maverick_pol in forum Qt Programming
    Replies: 7
    Last Post: 4th October 2007, 10:53

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.