问题描述
背景: 我正在实现一个应用程序,我需要在选定的行上进行仿射变换。线用 2 个点表示。所有代码都在鼠标事件中完成。
test1 = writer.get_extra_info('ssl_object')
der =test1.getpeercert(binary_form=True)
crtObj = crypto.load_certificate(crypto.FILETYPE_ASN1,der)
pubKeyObject = crtObj.get_pubkey()
pubKeyString = crypto.dump_publickey(crypto.FILETYPE_PEM,pubKeyObject)
我有两点,void mousepressEvent(){
lastPoint = event.point();
}
void mouseMoveEvent(){
currentPoint = event.point();
//Do transformations here.
translate_factor = currentPoint - lastPoint
scale_factor = currentPoint / lastPoint
rotation_angle = f(current_point,last_point) //FIND f
//Apply transformation
lastPoint = currentPoint
}
和 p1
。 X 轴从左到右增加。 Y 轴从上到下增加。我有一个点 p2
,我想围绕它旋转一组点 d
.
我如何找到从 p_set
到 p1
关于 p2
的旋转角度。
我正在做的是将 d
,p1
转换为 p2
并使用 -d
计算 theta,如下面的代码所示。
注意 y 是倒置的:从上到下。 这是代码
atan2f
当我使用它进行变换时,我得到了非常奇怪的旋转。 我想要的是找到角度作为当前点和最后点的函数
解决方法
在我看来,您正在寻找向量 p2-p1
的斜率。
如果我理解正确,您需要两个向量 p2-d
和 p1-d
的斜率差异,因此旋转角度类似于 atan((p2.y-d.y)/(p2.x-d.x)) - atan((p1.y-d.y)/(p1.x-d.x))