PDA

View Full Version : Translation problem while scaling an object



qlands
4th October 2010, 12:04
Hi,

I have a shape defined as:


myShape << QPointF(-50, -50) << QPointF(50, -50)
<< QPointF(50, 50) << QPointF(-50, 50)
<< QPointF(-50, -50);

Its starting matrix is identity:
|---|---|---|
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
|---|---|---|

When I dilate the shape to double its size with a TransformationPivotVector = (-50,0) I get the following matrix:

Matrix after Scale:
|----|---|---|
| 2 | 0 | 0 |
| 0 | 1 | 0 |
| 50 | 0 | 1 |
|----|---|---|

This means that the center of the shape has been translated by 50 units along the X axis.

Now, Giving that the shape currently has the matrix after scale, When I intent to contract the shape using a TransformationPivotVector = (50,0) the translation automatically becomes negative, see for example when I contract just 0.01 of the shape:

|-------|---|---|
| 1.99 | 0 | 0 |
| 0 | 1 | 0 |
| -49.5 | 0 | 1 |
|-------|---|---|

I use the following function to get an overall transformation matrix:


myShape->setTransform(QTransform().translate(transPivotVect or.x(), transPivotVector.y()).rotate(rotation).scale(xFact or, yFactor).translate(-transPivotVector.x(),-transPivotVector.y()));

The function basically gets a final matrix from: translate * rotate * scale * -translate.

I guess these function needs to include any previous translation of the object but I don’t know how.

Please help me!!

Many thanks in advance,
Carlos.