本页内容

QRotationReading Class

QRotationReading 类表示来自旋转传感器的单次读数。更多内容...

头文件: #include <QRotationReading>
CMake: find_package(Qt6 REQUIRED COMPONENTS Sensors)
target_link_libraries(mytarget PRIVATE Qt6::Sensors)
qmake: QT += sensors
继承自: QSensorReading

属性

  • x : qreal
  • y : qreal
  • z : qreal

公共函数

void setFromEuler(qreal x, qreal y, qreal z)
qreal x() const
qreal y() const
qreal z() const

详细说明

QRotationReading 单位

旋转读数包含 3 个角度,单位为度,用于定义设备在三维空间中的姿态。这些角度类似于偏航角、俯仰角和横滚角,但仅采用右手旋转规则进行定义,其轴系由右手笛卡尔坐标系确定。

设备相对于x、y和z轴进行了旋转,图中标出了旋转后的y2轴和y1轴以及旋转角度

这三个角度按以下顺序应用于设备。

  • 右手旋转 z (-180, 180]。从 y 轴开始,沿逆时针方向递增。
  • 右手旋转 x [-90, 90]。从新的(旋转一次后的)y 轴开始,朝 z 轴方向递增。
  • 右手旋转 y (-180, 180]。从新的(旋转过一次的)z 轴开始,并沿 x 轴方向递增。

下图直观展示了角度应用的顺序。

z 角度的 0 点被定义为一个固定的外部实体,且因设备而异。虽然通常使用磁北作为该参考点,但情况可能并非如此。请勿尝试比较不同设备之间的 z 角度值,即使是在同一设备上,如果该设备已移动了相当大的距离,也不应进行比较。

如果设备无法检测到固定的外部实体,z角度将始终为0,且QRotationSensor::hasZ 属性将被设置为false。

x 角和 y 角的 0 点定义为:当设备的 x 轴和 y 轴朝向地平线时。以下是一个示例,展示了 x 值如何随设备移动而变化。

图中所示设备以30、15、0、-15和-30度的x轴角度进行倾斜,展示其侧面轮廓

以下是一个示例,展示了y值如何随设备移动而变化。

图中所示设备从端面方向倾斜,倾斜角分别为-30、-15、0、15和30度

请注意,当 x 值为 90 或 -90 时,z 和 y 的数值会围绕同一轴旋转(这是由于运算顺序所致)。在这种情况下,y 旋转角将为 0。

属性文档

[read-only] x : qreal

该属性表示绕 x 轴的旋转角度。

单位为度。

访问函数:

qreal x() const

另请参阅 QRotationReading Units 。

[read-only] y : qreal

该属性表示绕 y 轴的旋转。

单位为度。

访问函数:

qreal y() const

另请参阅 QRotationReading Units 。

[read-only] z : qreal

该属性存储了围绕 z 轴的旋转角度。

单位为度。

访问函数:

qreal z() const

另请参阅 QRotationReading Units 。

成员函数文档

void QRotationReading::setFromEuler(qreal x, qreal y, qreal z)

根据三个欧拉角设置旋转。

此函数应由后端调用。

角度单位为度。旋转的顺序很重要,因为首先应用z 旋转,然后是x 旋转,最后是y 旋转。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.