使用协同,我们可以get the change in position of device using attitude, rotation using gyro。而要了解设备在三维空间中的实际位置,需要设备的初始位置,,,使userAcceleration、陀螺仪的数据能够在改变后得到新的实际位置。如何得到设备的初始实际位置。我想要检测的位置,如"45度向左倾斜,面朝上“或"45度向右倾斜,在y轴上旋转30度”。
发布于 2016-09-30 10:24:46
您可以使用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);不知何故,偏航仍然相对于你的设备的起始位置。为了解决这个问题,您应该使用Compass。
https://stackoverflow.com/questions/39787073
复制相似问题