Usage of gyroscope coremotion in iOS

Source: Internet
Author: User

Turn from: Http://code.eoe.cn/471/title/ios Juan elata Tsan coremotion fermium Archives Apply note
Readme.md external references to the original document

When we used to get acceleration in the iphone, we could only use the accelerometer module to get the gravitational acceleration, and then get the acceleration value by filtering. In fact, there is a gyroscope module in iOS, coremotion, more convenient to use.

DEVICEMOTION.M external Reference Original document//Initialize Coremotion
#import
Cmmotionmanager *motionmanager = [[Cmmotionmanager alloc]init];
1. Accelerometer Get phone acceleration data
Cmaccelerometerdata *newestaccel = Motionmanager.accelerometerdata;
Double accelerationx= newestaccel.acceleration.x;
Double accelerationy = NEWESTACCEL.ACCELERATION.Y;
Double Accelerationz = newestaccel.acceleration.z;
2. Gravity get the weight of the cell phone's gravity in all directions, according to this can get the space position of the mobile phone, tilt angle, such as double gravityx= motionmanager.devicemotion.gravity.x;
Double gravityy= motionmanager.devicemotion.gravity.y;
Double gravityz= motionmanager.devicemotion.gravity.z;
To get the tilt angle of the phone:
Double Ztheta= atan2 (Gravityz,sqrtf (gravityx*gravityx+gravityy*gravityy))/m_pi*180.0;
Double xytheta= atan2 (gravityx,gravityy)/m_pi*180.0;
Ztheta is the angle between the cell phone and the horizontal plane, and the Xytheta is the mobile phone's rotation around itself.
3. Devicemotion acquisition of gyroscope data including angular velocity, space position, etc.
Rotational angular velocity:
Cmrotationrate rotationrate= motionManager.deviceMotion.rotationRate;
Double RotationX = rotationrate.x;
Double RotationY = rotationrate.y;
Double RotationZ = rotationrate.z;
The Euler angle of the spatial position (the angle between two moments of the mobile phone can be calculated by Euler angle, which is more accurate than the angular velocity)
Double roll= MotionManager.deviceMotion.attitude.roll;
Double pitch =motionmanager.devicemotion.attitude.pitch;
Double yaw= MotionManager.deviceMotion.attitude.yaw;
Four-dollar space position (similar to Euler's angle, but solves the deadlock problem of universal joints)
Double w= MOTIONMANAGER.DEVICEMOTION.ATTITUDE.QUATERNION.W;
Double wx= motionmanager.devicemotion.attitude.quaternion.x;
Double wy= motionmanager.devicemotion.attitude.quaternion.y;
Double wz =motionmanager.devicemotion.attitude.quaternion.z;
The gyroscope module can be used to simulate the car, simulate shooting and so on.

Usage of gyroscope coremotion in iOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.