如何计算四元数旋转和指定轴的角度?

问题描述 投票:0回答:2

我试图基于沿着指定四元数旋转的同一轴的四元数旋转分量,围绕一个轴(任意单位矢量,不一定是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);
}

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

我已经挖了谷歌试图找到答案,但我还没有找到解决方案。任何帮助表示赞赏。

c# unity3d axis angle quaternions
2个回答
1
投票

我解释你的问题的方式是,如果你有一组旋转点,它们会以什么角度绕另一个轴移动。

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

Rotation

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


0
投票

这是我想要的代码:

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);
}
© www.soinside.com 2019 - 2024. All rights reserved.