How to calculate transformation using coordinates

2019-09-20 08:20发布

问题:

Hello friends I am working on a project and I have a problem. See Images below

This purple rectangle is my main region which I want to rotate and transform. I have rotated this using Qtransform rotate at 30 degrees and has size(180,173). I have calculated the cords of inner region and pass those to paint event and when I resize outer Rectangle this inner rectangle is drawn using painterpath see image below Now this purple region in img 2 looks like transformed because I have drawn only cords when I reduced the size of outer rectacle.

So my question is, Is there any method to calculate at what angle inner region gets transformed If yes please help me guys.

回答1:

I assume you are able to get coordinates of target figure (after applying the transform). You can get the angle (in radiance) between a vector and the X axis using atan2 function:

QPointF vector = vector_end - vector_start;
double angle = atan2(vector.y(), vector.x());

Difference of angle values of two vectors will give you angle between those two vectors. You may need to make sure that the difference is in [0, 2π] range by adding or substracting 2π.