来自 Android 传感器的 -Z 轴的偏航、俯仰、横滚

发布于 2024-12-28 20:03:04 字数 202 浏览 3 评论 0原文

我们从 android 的 SensorManager.getOrientation() 获得的偏航俯仰和横滚都是针对手机的 Y 轴。我的意思是,偏航和俯仰表示 Y 轴指向的位置,而滚动则绕 Y 轴指向。 (我的屏幕方向固定为横向,因此 Y 轴不会改变)。但我想要的是负 Z 轴的偏航俯仰和滚动(指向手机),更像是如果我的手机屏幕是飞机驾驶舱中的横向窗口,那么偏航会是多少俯仰和横滚是什么?

The yaw pitch and roll we get from the android's SensorManager.getOrientation() are all for the Y axis of the phone. By this i mean, the yaw and pitch say where the Y-axis points, and the roll is about the Y axis. (and my screen orientation is fixed to landsape, so the Y axis doesnt change). But what i want is the yaw pitch and roll of the negative Z axis (points into the phone), more like if my phone screen is a landscape window in a cockpit of a plane, what would the yaw pitch and roll be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栖竹 2025-01-04 20:03:04

如果我理解你的意思,你会看到当前的偏航俯仰和横滚正在返回,就好像 +y 轴是默认的“前”向量,+z 轴是默认的“上”向量。您想要进行坐标变换,以便使用 -z 轴作为默认的“前”向量和 +x 轴作为默认的“上”向量来计算偏航、俯仰和滚转。

首先,您需要根据当前配置中的偏航、俯仰和滚转计算当前的前向和向上矢量。这可以使用 3D 旋转矩阵来完成:
http://en.wikipedia.org/wiki/Rotation_matrix#Rotations_in_third_dimensions

使用偏航角围绕 z 旋转,俯仰为围绕 x 旋转,滚动为围绕 y 旋转。将这些矩阵相乘,然后将前向量 (0, 1, 0) 和上向量 (0, 0, 1) 乘以结果以获得新的前向量和上向量。

接下来,您需要计算新的偏航角、俯仰角和滚动角。偏航是投影到 yz 平面的前向矢量(将 x 值设置为 0)与 -z 矢量 (0, 0, -1) 之间的角度,俯仰是投影到 xz 平面的前向矢量与 -z 之间的角度z 向量,roll 是投影到 xy 平面上的向上向量与 +x 向量 (1, 0, 0) 之间的角度。如果我们让 Fx = 前向量的 x 分量,Fy 为 y 分量,依此类推,我们会得到:

yaw   = acos ( -z dot (0,  Fy, Fz) ) / sqrt(Fy*Fy + Fz*Fz)
pitch = acos ( -z dot (Fx, 0,  Fz) ) / sqrt(Fx*Fx + Fz*Fz)
roll  = acos ( +x dot (Ux, Uy, 0 ) ) / sqrt(Ux*Ux + Uy*Uy)

如果我选择了错误的向量,你应该能够对其他向量执行此操作。

If I understand what you're saying, you are seeing the current yaw pitch and roll being return as if the +y axis were the default 'front' vector and the +z axis were the default 'up' vector. You would like to do a coordinate transform such that your yaw, pitch, and roll are calculated with the -z axis as the default 'front' vector and the +x vector as the default 'up' vector.

First, you'll need to compute the current front and up vectors from your yaw, pitch and roll in the current configuration. This can be done using 3D rotation matrices:
http://en.wikipedia.org/wiki/Rotation_matrix#Rotations_in_three_dimensions

Use the yaw angle to rotate about z, pitch as a rotation about x, and roll as a rotation about y. Multiply these matrices together, then multiply the front vector (0, 1, 0) and up vector (0, 0, 1) by the result to get your new front and up vectors.

Next you'll need to compute the new yaw, pitch, and roll angles. Yaw is the angle between the front vector projected into the yz plane (set x value to 0) and the -z vector (0, 0, -1), pitch is the angle between the front vector projected onto the xz plane and the -z vector, and roll is the angle between the up vector projected onto the xy plane and the +x vector (1, 0, 0). If we let Fx = the x component of the front vector, Fy be the y component, and so on, we get:

yaw   = acos ( -z dot (0,  Fy, Fz) ) / sqrt(Fy*Fy + Fz*Fz)
pitch = acos ( -z dot (Fx, 0,  Fz) ) / sqrt(Fx*Fx + Fz*Fz)
roll  = acos ( +x dot (Ux, Uy, 0 ) ) / sqrt(Ux*Ux + Uy*Uy)

You should be able to do this for other vectors if I've chosen the wrong ones.

海之角 2025-01-04 20:03:04

Android 中使用的身体轴约定与航空航天中使用的不同(有充分的理由)。 “平面”的 x 轴相当于 Android 设备的“y”轴(同样,x 轴与 y 轴相关,正或负取决于 ENU 或 NED 约定)。可以在这里找到一篇关于偏航、俯仰和横滚约定的好文章,这可能是回答您的问题的开始:http://www.sensorplatforms.com/understanding-orientation-conventions-mobile-platforms/

The body axes conventions used in Android are not the same as used in aerospace (for good reasons). The x-axis of a "plane" is equivalent to the "y" axis of and Android device (and likewise x axis is related to y axis, positive or negative depending on ENU ro NED conevntions). A good article on Yaw Pitch ans Roll conventions can be found here, and may be a start toward answering your question: http://www.sensorplatforms.com/understanding-orientation-conventions-mobile-platforms/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文