0

我在 IOS 中使用核心运动来计算 ipad 和俯仰滚动层之间的角度,但我不知道如何根据偏航、俯仰和滚动值计算 ipad 层和俯仰滚动层之间的角度。在下图中,我想计算 α - 角度。请帮我!谢谢

下面的计算正确吗?

α = 90 - atan2(sqrt(pow(acceleration.x,2)+pow(acceleration.y,2)),acceleration.z)

http://imageshack.us/photo/my-images/443/bild1nwcmm.png/

PS:红线是我的ipad-layer

4

1 回答 1

0

任务不清楚。从 CoreMotion,您可以获得当前的设备姿态 (CMMotionManager.deviceMotion.attitude),然后将其用作参考点(零),以便获得滚动、俯仰和偏航的增量角度 (CMAttitude multiplyByInverseOfAttitude:)。

@interface OrientationTracker : NSObject {
    CMMotionManager* motionManger;
    CMAttitude* referenceAttitude;
}

- (void)markZeroReference
{
    CMDeviceMotion* deviceMotion = self.motionManager.deviceMotion;
    self.referenceAttitude = [deviceMotion.attitude];
}

- (CMAttitude*)currentOrientation {
    return [self.motionManager.deviceMotion.attitude multiplyByInverseOfAttitude:self.referenceAttitude];
}
于 2012-01-02T10:38:20.663 回答