【问题标题】:Getting the rotation of device around the world origin's y axis in ARKit在 ARKit 中获取设备绕世界原点 y 轴的旋转
【发布时间】:2019-02-26 20:09:46
【问题描述】:

当我在 ARKit 中绕 y 轴旋转我的设备时,我试图计算它的旋转。为澄清起见,ARKit 中的 y 轴是垂直于地面向上指向的轴。

我使用 eulerangles 来获得这样的相机旋转:

var alpha = sceneView.pointOfView?.eulerAngles.y

这在0=<alpha<pi/2 and when -pi/2<alpha<=0 时大致有效,但是对于应该是其他角度的情况,我得到了错误的读数。我怀疑这与万向节锁定有关,并且我必须以某种方式使用四元数才能获得正确的角度,而不管象限如何。非常感谢任何帮助!

【问题讨论】:

  • 欧拉角的范围取决于您定义的顺序。对于欧拉角,旋转顺序很重要(即使角度值相同,X、Y、Z 或 X、Z、Y 也不能描述相同的 3D 旋转)。那么你到底想做什么?我想你已经读过这个了? en.wikipedia.org/wiki/…
  • 我试图让我的设备在 ARKit 中在静止并环顾四周时绕 Y 轴旋转的角度。我需要获得 0 到 360 度范围内的角度,而我没有使用 eulerangles 来管理。但是,我改为使用四元数计算来解决它。

标签: ios math 3d arkit euler-angles


【解决方案1】:

通过使用四元数而不是欧拉角来解决它。这是我使用的代码:

  guard let cameraNode = sceneView.pointOfView else { return }

  //Get camera orientation expressed as a quaternion
  let q = cameraNode.orientation

  //Calculate rotation around y-axis (heading) from quaternion and convert angle so that
  //0 is along -z-axis (forward in SceneKit) and positive angle is clockwise rotation.
  let alpha = Float.pi - atan2f( (2*q.y*q.w)-(2*q.x*q.z), 1-(2*pow(q.y,2))-(2*pow(q.z,2)) )

我使用了this website 上列出的四元数到标题/欧拉的转换。

【讨论】:

  • 谢谢。这正是我解决万向节锁定问题所需要的。虽然,我不得不使用相同的公式,但没有先做“pi - ...”。我想这只是你从哪里开始测量旋转角度和方向的问题。
猜你喜欢
  • 2019-10-18
  • 1970-01-01
  • 2015-04-11
  • 2015-07-23
  • 2016-10-20
  • 2017-07-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多