简体   繁体   English

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

[英]How to calculate the angle given a quaternion rotation and a specified axis?

I'm trying to rotate an object around only one axis (any arbitrary unit vector, not necessarily x, y or z), based on the quaternion rotation component along the same axis of a specified quaternion rotation.我试图根据沿着指定四元数旋转的同一轴的四元数旋转分量,仅围绕一个轴(任何任意单位向量,不一定是 x、y 或 z)旋转对象。

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

I don't know how to obtain the angle of my quaternion's rotation that is only along the specified axis.我不知道如何获取仅沿指定轴的四元数旋转角度。 I could do it when the axis is y, for example:我可以在轴为 y 时执行此操作,例如:

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

I want to replicate the results of the above, but for any given axis.我想复制上面的结果,但对于任何给定的轴。

I've dug into google trying to find the answer to this but I haven't found a solution.我已经深入谷歌试图找到这个问题的答案,但我还没有找到解决方案。 Any help is appreciated.任何帮助表示赞赏。

The way I am interpreting your question is that if you have a set of rotating points, by what angle would they move around some other axis.我解释你的问题的方式是,如果你有一组旋转点,它们将以什么角度绕其他轴移动。

The only issue with this is that the angle from a different axis actually depends on which point you are looking at.唯一的问题是来自不同轴的角度实际上取决于您正在查看的点。

回转

However, something you could try is to represent your rotation as an axis angle (ω, θ) , then take the dot product with your axis v to get a new angle of θ scaled by wv .但是,您可以尝试将旋转表示为轴角(ω, θ) ,然后将点积与轴v进行比较,以获得按wv缩放的新角度θ This might not be what you want, but if you add details with more details on what you are trying to achieve, we might be able to help you better.这可能不是您想要的,但如果您添加更多关于您想要实现的目标的详细信息,我们可能会更好地帮助您。

Here is the code I wanted:这是我想要的代码:

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);
}

Then angle of rotation from a unit-quaternion (w,x,y,z) also written w+xi+yj+zk is arccos(w)*2 .然后单位四元数(w,x,y,z)的旋转角度也写为w+xi+yj+zkarccos(w)*2

If the angle is > 0, the direction is (x,y,z)/sin( arccos(w)/2 ) otherwise there is no specific direction, and the rotation is identity around any axis;如果角度 > 0,则方向为(x,y,z)/sin( arccos(w)/2 )否则没有特定方向,旋转绕任意轴恒等式; 0 angle is no rotation 0 角度不旋转

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM