【发布时间】:2021-04-06 15:59:02
【问题描述】:
背景: 我正在实现一个应用程序,我需要在选定的行上进行仿射变换。线用 2 个点表示。所有代码都在鼠标事件中完成。
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 和 p2。 X 轴从左到右递增。 Y 轴自上而下递增。我有一个点d,我想围绕它旋转一组点p_set。
如何找到从p1 到p2 关于d 的旋转角度。
我正在做的是将p1、p2 转换为-d 并使用atan2f 计算theta,如下面的代码所示。
请注意,y 是倒置的:从上到下。 这是代码
const auto about = stroke->getMidPoint();
Eigen::Affine2f t1(Eigen::Translation2f(0-about.x(),0-about.y()));
Eigen::Vector3f p1 = t1.matrix()*Eigen::Vector3f(lastPoint.x(),lastPoint.y(),1.0);
Eigen::Vector3f p2 = t1.matrix()*Eigen::Vector3f(currentPoint.x(),currentPoint.y(),1.0);
float theta = atan2f(p2[1]-p1[1],p2[0]-p1[0]);
当我使用它进行变换时,我得到了非常奇怪的旋转。 我想要的是找到角度作为当前点和最后一点的函数
【问题讨论】:
-
听起来更像是三角问题而不是 C++ 问题...
-
你关心旋转方向吗?您可以选择任意一种方式,也可以转多圈。这很重要吗?
-
@PeteBlackerThe3rd 我已经添加了我需要这个的背景。是的,它们很重要
标签: graphics trigonometry eigen3 coordinate-systems