旋转Atan2 CCW CW连续性

Rotation Atan2 CCW CW continuity

本文关键字:连续性 CW CCW Atan2 旋转      更新时间:2023-10-16

这就是我拥有的

  • 我有一个平面在2D X,Y
  • 我通过点击屏幕X',Y'来设置他的目的地
  • 我计算了它需要转向以面对这个目的地的角度:
// Calculate the angle between plane position and destination point
CVector3 facingVec = m_vDestination - m_vPosition;
fAngle = -Math::radiansToDegrees (  (float)atan2f(m_vDestination.x - m_vPosition.x, m_vDestination.y - m_vPosition.y)  )  ;
//This doesn't work, when rotating from ex. 350 degree to 0 
//plane has to go all the way around 360,350,340,330,
//...,120,...100,90,..down to zero
float angleToTurn = fAngle - m_fRotationAngle;
if(angleToTurn < 0)
{
    angleToTurn += 360.0f;
}
m_fRotationAngle += (angleToTurn) / 5;
// Move the unit towards the calculated angle m_fRotationAngle
m_vDirection.x =   (-sin(Math::degreesToRadians(m_fRotationAngle)));
m_vDirection.y =   (cos(Math::degreesToRadians(m_fRotationAngle)));
m_vPosition += ( 2 * m_vDirection * fDelta);

这就是它的样子

YT视频-很抱歉演示版,我现在无法获得任何免费内容。

这就是我需要的

  • 我需要这个来表现正常,比方说平面以350度角旋转。我设置了目的地,新角度应该是15

不去:350340330320310300290,。。。10,0.15它应该继续:350,0,15

希望你能帮我对付这些家伙,我已经放弃了bezier的方法——几天以来我一直在努力。

如果我读对了,你想在两个向量之间找到插值的最小角度吗?如果是这样,以下算法应该有效:

  1. 求第一个向量相对于固定向量[1,0]的角度。这是a1
  2. 求第二个向量相对于固定向量[1,0]的角度。这是a2
  3. 设da=a2-a1
  4. 如果da>180,da-=360
  5. 否则如果da<180,da+=360

您需要计算相对于另一个第三矢量[1,0]的角度,以便确定向左或向右旋转的天气。

编辑:我看到你的YouTube链接断了,现在我看到它又工作了。我想我的答案是你想要什么。