Join Steven Lipton for an in-depth discussion in this video Measurement units, part of Advanced iOS App Development: Core Motion.
- [Instructor] There's a lot of different units of measurements with core motion, many of them from physics and math. You probably haven't had a physics or math class in awhile, so you might want a refresher. Put an iPhone on a table with the screen facing up, and the bottom facing you, like this. There are three axes going through your phone based on this position. The X-Axis goes through one side of the phone to the other. Side to side motion is measured on the X-Axis. IPhone measurements are in meters based on a center reference position.
The values increase as you go right and decrease as you go left. When you move the phone 10 centimeters to the left, that would be a movement of negative zero point one meters. The Y-Axis is a motion from the top to the bottom of the phone. The values on the Y-Axis increase as you go away from you and decrease as they get closer to you. Moving the phone a foot away from you is about a zero point three meter change in the Y-Axis.
The Z-Axis is the up and down movement. The values of the Z-Axis position increases going up and decreases going down. If I drop my phone from a normal table, the value for Z's position would change by about negative point seven six meters. When you rotate a phone, you rotate along the same three axes. We call a rotated position an attitude. You'll hear three more terms about rotation and attitude; pitch, roll, and yaw.
The pitch is the rotation around the X-Axis. The roll is the rotation around the Y-Axis. The yaw is the rotation around the Z-Axis. Most people are familiar with the common measure of angle known as degrees. Degrees split up a circle into 360 units. Your rotation is a measure of those 360 units. However, IOS as a standard, uses radians instead of degrees. Radians are a measure based on a value of two times the value of pi.
When working with rotations, radians are actually easier to work with, and therefore, the standard. You can get a pretty accurate value in your Swift code my multiplying by the constant double dot pi. We'll be working with radians as doubles, which are not easy for most people to read when printed to the console. You'll see here a quick conversion chart. Since radians deal with pi, these numbers have infinite decimal points. You might want to remember a few rough estimates of radians to read data correctly if sending to the console.
On this conversion chart, I rounded to the first decimal. These are very rough approximations. If you try to add zero point five radians three times, or 30 degrees three times to make 90 degrees, they don't add up correctly to one point six. Use these to estimate your data and debugging. When you start combining three D coordinates and three D rotations, there's a few things you need to be careful of. Once you start rotating the phone, the axes follow the motion. A roll of 45 degrees, which is a one quarter pi in radians, mean your X-Axis has rotated 45 degrees.
It is no longer side to side movement, but up to the right and down to the left. When you describe motion, remember that the X, Y, and Z axes move with the phone. We don't often talk about absolute measurements in core motion, like one quarter pi. Instead, we talk about change and rates of change. When we start talking about changes in motion, we are talking physics. Let's now look at some basic physics you'll need to know for core motion.
- Reading Core Motion data
- Understanding Core Motion methods
- Creating a pedometer app
- Using pace and distance data from Core Motion
- Pushing and pulling device motion data
- Accessing the altitude sensors
- Working with the motion activity manager (CMMotionActivityManager)