【问题标题】:Detect initial position of iOS Device in 3D Space - Core Motion检测 iOS 设备在 3D 空间中的初始位置 - Core Motion
【发布时间】:2016-09-30 08:33:38
【问题描述】:
使用 Coremotion,我们可以get the change in position of device using attitude, rotation using gyro。 但是要知道设备在 3D 空间中的实际位置,我们需要设备的初始位置。 以便相应地应用用户加速度,陀螺仪数据可以在更改后得到新的实际位置。如何获取设备的初始实际位置。我想检测像“向左倾斜 45 度,面朝上”或“向右倾斜 45 度,在 y 轴上旋转 30 度”这样的位置。
【问题讨论】:
标签:
ios
iphone
core-motion
sensor-fusion
【解决方案1】:
您可以使用 CoreMotion 加速度计通过一些方程式来估计设备的初始位置。
let x = data.acceleration.x
let y = data.acceleration.y
let z = data.acceleration.z
let roll = atan (y / sqrt(pow(x,2.0) + pow(z, 2.0)));
let pitch = atan (x / sqrt(pow(y, 2.0) + pow(z, 2.0)));
let yaw = atan (sqrt(pow(x, 2.0) + pow(z, 2.0))/z);
不知何故,Yaw 仍然相对于您设备的起始位置。为了解决这个问题,您应该寻找使用指南针。