本文介绍了如何使用矩形坐标计算变换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友我正在做一个项目,我有一个问题。
查看以下图片

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

这个紫色矩形是我想要旋转和变换的主要区域。我已经旋转这使用Qtransform旋转30度,具有大小(180,173)。我已经计算了内部区域的线,并传递那些绘制事件,当我调整外部Rectangle这个内部矩形绘制使用painterpath请参见下面的图像

现在,img 2中的这个紫色区域看起来像是变形的,因为我在缩小外部正方形的大小时只绘制了线。

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

推荐答案

我假设你能够得到目标图的坐标(应用变换后)。您可以使用 atan2 函数获得向量和X轴之间的角度(以弧度表示):

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());

两个向量的差异 angle 给你这两个向量之间的角度。您可能需要通过添加或减去2π来确保差值在[0,2π]范围内。

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

这篇关于如何使用矩形坐标计算变换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:14
查看更多