How to calculate transformation using coordinates of rectangle?

梦想与她 提交于 2019-12-13 08:16:30

问题


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



来源:https://stackoverflow.com/questions/29671481/how-to-calculate-transformation-using-coordinates-of-rectangle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!