How to calculate transformation using coordinates

2019-09-20 07:51发布

Hello friends I am working on a project and I have a problem. See Images below enter image description here

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 enter image description here 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条回答
The star\"
2楼-- · 2019-09-20 08:36

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π.

查看更多
登录 后发表回答