【问题标题】:How to calculate the angle given a quaternion rotation and a specified axis?如何计算给定四元数旋转和指定轴的角度?
【发布时间】:2019-09-08 08:51:41
【问题描述】:

我正在尝试基于沿指定四元数旋转的同一轴的四元数旋转分量,仅围绕一个轴(任何任意单位向量,不一定是 x、y 或 z)旋转对象。

public void Rotate(Quaternion rotation, Vector3 axis, Vector3 pointToRotateAround)
{
     float angle = ?
     gameObject.transform.RotateAround(pointToRotateAround, axis, angle);
}

我不知道如何获得仅沿指定轴的四元数旋转角度。我可以在轴为 y 时这样做,例如:

public void Rotate(Quaternion rotation, Vector3 pointToRotateAround)
{
     gameObject.transform.RotateAround(pointToRotateAround, Vector3.up, rotation.eulerAngles.y);
}

我想复制上面的结果,但是对于任何给定的轴。

我已经深入谷歌试图找到这个问题的答案,但我还没有找到解决方案。任何帮助表示赞赏。

【问题讨论】:

  • 请提供更多信息,说明您想如何使用它以及用于什么目的。目前这听起来有点像XY problem。为什么您明确需要 Quaternion 作为输入?

标签: c# unity3d axis angle quaternions


【解决方案1】:

那么单位四元数(w,x,y,z) 的旋转角度也写成w+xi+yj+zkarccos(w)*2

如果角度>0,则方向为(x,y,z)/sin( arccos(w)/2 ),否则无特定方向,绕任意轴旋转为同一性; 0角不旋转

【讨论】:

    【解决方案2】:

    这是我想要的代码:

    public void Rotate(Quaternion rotation, Vector3 axis, Vector3 pointToRotateAround)
    {
         float angle;
         Vector3 rotAxis;
    
         rotation.ToAngleAxis(out angle, out rotAxis);
    
         float angleAroundAxis = Vector3.Dot(rotAxis, axis);
    
         gameObject.transform.RotateAround(pointToRotateAround, axis, angleAroundAxis);
    }
    

    【讨论】:

      【解决方案3】:

      我解释您的问题的方式是,如果您有一组旋转点,它们将围绕其他轴移动什么角度。

      唯一的问题是来自不同轴的角度实际上取决于您正在查看的点。

      但是,您可以尝试将您的旋转表示为轴角度(ω, θ),然后将您的轴与v 的点积得到一个新角度θ,并按w.v 缩放。这可能不是您想要的,但如果您添加详细信息以及您想要实现的目标的更多详细信息,我们可能会为您提供更好的帮助。

      【讨论】:

      • 这正是我需要的,谢谢!现在看来很明显了。
      猜你喜欢
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 2020-10-02
      • 1970-01-01
      • 2012-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多