如何将四元数转换为角度? [英] How can I convert a Quaternion to an angle?

查看:243
本文介绍了如何将四元数转换为角度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 https://docs.microsoft.com/en-us/xamarin/essentials/orientation-sensor 计算设备的俯仰、偏航和滚转.图书馆工作,并以四元数返回.

I'm trying to use this library at https://docs.microsoft.com/en-us/xamarin/essentials/orientation-sensor to work out the devices pitch, yaw, and roll. The library works, and returns in a Quaternion.

我希望能够将这个四元数转换为 360 度空间中的俯仰、偏航和滚动,以及设备向"360 度旋转多远的 0 到 100 的百分比.

I want to be able to convert this quaternion to a pitch, yaw, and roll in 360 degree space, and also a percentage from 0 to 100 of how far the device has been rotated "towards" 360.

我一直在研究这一点,并发现了各种以数学符号表示的数学方程,以说明如何实现这样的目标.这些文档还讨论了欧拉角、弧度和其他各种我没有任何概念的概念.

I've been researching this and have found various mathematical equations, expressed in mathamatical notation, of how to achieve something like this. These documents also talk about things like euler angles, rads, and various other concepts that I don't have any concept of.

在 C# 中是否有一种方法可以将四元数转换为 a) 360 度空间中的角度,以及 b) 设备在某个轴上旋转的 0-100 百分比?

Is there a way in C# to convert from a Quaternion to both a) an angle in 360 degrees space, and b) a 0-100 percentage of how rotated the device is on a certain axis?

谢谢!

推荐答案

根据 文档:

四元数值与绕轴的旋转密切相关.如果旋转轴是归一化矢量 (ax, ay, az),并且旋转角度是 Θ,那么 (X, Y, Z, W) 分量四元数是:

A Quaternion value is very closely related to rotation around an axis. If an axis of rotation is the normalized vector (ax, ay, az), and the rotation angle is Θ, then the (X, Y, Z, W) components of the quaternion are:

(ax·sin(Θ/2), ay·sin(Θ/2), az·sin(Θ/2), cos(Θ/2))

(ax·sin(Θ/2), ay·sin(Θ/2), az·sin(Θ/2), cos(Θ/2))

首先从W中得到Θ:

var Θ = Math.Acos(W)*2;

然后,通过:

var ax = X / Math.Sin(Math.Acos(Θ));
var ay = Y / Math.Sin(Math.Acos(Θ));
var az = Z / Math.Sin(Math.Acos(Θ));

四元数的轴角为 [ax, ay, az].

The Axis Angle of the Quaternion is [ax, ay, az].

例如,[0,0,0.7071068,0.7071068]QuaternionAxis-Angle[0,0,1].您可以认为它在 Z 轴上旋转了 90 度.

For example, a Quaternion of [0,0,0.7071068,0.7071068] will have an Axis-Angle of [0,0,1]. You could consider it rotated 90 degrees on the Z axis.

这篇关于如何将四元数转换为角度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆