View Full Version : the invert of a QTransform's transposed
calmspeaker
13th January 2011, 02:57
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.
calmspeaker
17th January 2011, 01:09
The main.cpp is
#include <QtGui>
void showmat(QTransform abc){
qDebug("%s",QString("%1,%2,%3").arg(abc.m11()).arg(abc.m12()).arg(abc.m13()).toL ocal8Bit().data());
qDebug("%s",QString("%1,%2,%3").arg(abc.m21()).arg(abc.m22()).arg(abc.m23()).toL ocal8Bit().data());
qDebug("%s",QString("%1,%2,%3").arg(abc.m31()).arg(abc.m32()).arg(abc.m33()).toL ocal8Bit().data());
}
int main()
{
QTransform a(1,0,300,0,1,300,0,0,1);
QTransform temp = QTransform(1,0,0,0,1,0,0,0,1).translate(300,300).t ransposed();//m_pItem->sceneTransform().transposed();
QTransform temp1 = QTransform(1,0,0,0,1,0,0,0,1).translate(300,300); //m_pItem->sceneTransform();
qDebug("is invertible? %d",temp.isInvertible()?1:0);
qDebug("is equal the made one? %d",temp == a?1:0);
qDebug("-----temp------");
showmat(temp);
QTransform abc = temp.inverted();
qDebug("----temp invert-------");
showmat(abc);
qDebug("-----temp1------");
showmat(temp1);
qDebug("-----temp1 invert ------");
showmat(temp1.inverted());
qDebug("-----------");
showmat(a);
QTransform a1 = a.inverted();
qDebug("-----------");
showmat(a1);
}
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?
marcvanriet
17th January 2011, 01:53
Just something off-topic : instead of
qDebug("%s",QString("%1,%2,%3").arg(abc.m31()).arg(abc.m32()).arg(abc.m33()).toL ocal8Bit().data());
you can write this :
qDebug() << abc.m31() << abc.m32() << abc.m33();
Is a lot more convenient and readable.
Regards,
Marc
calmspeaker
17th January 2011, 03:19
Just something off-topic : instead of
qDebug("%s",QString("%1,%2,%3").arg(abc.m31()).arg(abc.m32()).arg(abc.m33()).toL ocal8Bit().data());
you can write this :
qDebug() << abc.m31() << abc.m32() << abc.m33();
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.
#include <QtGui>
void showmat(QTransform abc){
qDebug("%s",QString("%1,%2,%3").arg(abc.m11()).arg(abc.m12()).arg(abc.m13()).toL ocal8Bit().data());
qDebug("%s",QString("%1,%2,%3").arg(abc.m21()).arg(abc.m22()).arg(abc.m23()).toL ocal8Bit().data());
qDebug("%s",QString("%1,%2,%3").arg(abc.m31()).arg(abc.m32()).arg(abc.m33()).toL ocal8Bit().data());
}
int main()
{
QTransform a(1,0,300,0,1,300,0,0,1);
//QTransform temp = QTransform(1,0,0,0,1,0,0,0,1).translate(300,300).t ransposed();//m_pItem->sceneTransform().transposed();
QTransform temp1 = QTransform(1,0,0,0,1,0,0,0,1).translate(300,300); //m_pItem->sceneTransform();
//QTransform temp = temp1.transposed();
QTransform temp(temp1.m11(),temp1.m21(),temp1.m31(),temp1.m12 (),temp1.m22(),temp1.m32(),temp1.m13(),temp1.m23() ,temp1.m33());
qDebug("is invertible? %d",temp.isInvertible()?1:0);
qDebug("is equal the made one? %d",temp == a?1:0);
qDebug("-----temp------");
showmat(temp);
qDebug("temp's Txtype = %d",temp.type());
QTransform abc = temp.inverted();
qDebug("----temp invert-------");
showmat(abc);
qDebug("-----temp1------");
showmat(temp1);
qDebug("-----temp1 invert ------");
showmat(temp1.inverted());
qDebug("-----------");
showmat(a);
qDebug("a's Txtype = %d",temp.type());
QTransform a1 = a.inverted();
qDebug("-----------");
showmat(a1);
}
But I donnot know why!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.